惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
N
News and Events Feed by Topic
Cloudbric
Cloudbric
B
Blog
Cisco Talos Blog
Cisco Talos Blog
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
V
Visual Studio Blog
A
Arctic Wolf
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
S
Security @ Cisco Blogs
博客园 - 聂微东
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
量子位
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tenable Blog
月光博客
月光博客
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
D
Docker
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Help Net Security
Help Net Security
D
DataBreaches.Net

博客园 - 殇

java设计模式基础之设计原则 java--callback GEF七天之第五天 java基础--特殊的String GEF七天之第四天 GEF七天之第三天 GEF七天之第二天 GEF七天之第一天 网络编程--简单实现javaftp服务器 网络编程--ftp客户端的实现(c#版) c#套接字的实现 好东西大家分享: JAVA学习的一些重点 最基础的数据结构(转自程序员杂志) java面试算法题(经典) (转)JSP上传视频后自动转成flv的核心JAVA方法 2008年1月编程语言排名(转) 利用Render方法生成静态页 (转)实现struts2的CRUD中的权限控制(二) (转)实现struts2的CRUD中的权限控制(一)
距离矢量路由算法(最短路Bellman-Ford实现)实现
· 2008-05-25 · via 博客园 - 殇

using   namespace  std;

 
const   int  MAXN  =   100 ;
 
const   int  MAXV  =  MAXN  *  MAXN;
 
const   int  INF  =   2000000000 ;

 
struct  EDGE
  
{
     
int  u, v;
}
 ;

 
int  g[MAXN][MAXN];
EDGE e[MAXV];

 
int  BellmanFord( int  beg,  int  end,  int  nNum,  int  eNum)
  
// nNum为顶点数, eNum为边数, 复杂度O(VE) 
      int  d[MAXN];
     
int  i, k;

     
for  (i = 0 ; i < nNum; i ++ )
        d[i]  
=  INF;
    d[beg]  
=   0 ;
    
     
bool  ex  =   true ;
     
for  (k = 1 ; k < nNum  &&  ex; k ++ )
      
{
        ex  
=   false ;
         
for  (i = 0 ; i < eNum; i ++ )
             
if  (d[e[i].u]  <  INF  &&  d[e[i].v]  >  d[e[i].u]  +  g[e[i].u][e[i].v])
              
{
                d[e[i].v]  
=  d[e[i].u]  +  g[e[i].u][e[i].v];
                ex  
=   true ;
            }
 
    }
 
 
     
return  d[end];
}
 
 
 
int  main()
  
{
     
int  i, j;
     
int  t  =   0 ;
     
int  eNum  =   0 ;
     
int  nNum  =   9 ;
     
for  (i = 0 ; i < 4 ; i ++ )
         
for  (j = 0 ; j < 4 ; j ++ )
          
{
             
if  (i  ==  j) 
              
{
                g[i][j]  
=  INF;
            }
 
             
else 
               
{
                g[i][j]  
=   ++ t;
                e[eNum].u  
=  i;
                e[eNum].v  
=  j;
                eNum 
++ ;
            }
 
        }
     
    cout  
<<  BellmanFord( 2 ,  3 , nNum, eNum)  <<  endl;
     
return   0 ;
}