标签:
1 void spfa() 2 { 3 queue<int>q; 4 d[1]=0; 5 q.push(1); 6 while (!q.empty()) 7 { 8 int u=q.front(); 9 q.pop(); 10 vs[u]=false; 11 for (int i=head[u];i!=-1;i=eage[i].next) 12 { 13 int v=eage[i].v; 14 int w=eage[i].w; 15 if (d[v]>d[u]+w) 16 { 17 d[v]=d[u]+w; 18 if (!vs[v]) 19 { 20 vs[v]=true; 21 q.push(v); 22 } 23 } 24 } 25 } 26 }
标签:
原文地址:http://www.cnblogs.com/pblr/p/5719614.html