1 ///spfa模板 2 void spfa() 3 { 4 queue<int>q; 5 d[1]=0; 6 q.push(1); 7 while (!q.empty()) 8 { 9 int u=q.front(); 10 q.pop(); 11 vs[u]=false; 12 for (int i=head[u];i!=-1;i=eage[i].next) 13 { 14 int v=eage[i].v; 15 int w=eage[i].w; 16 if (d[v]>d[u]+w) 17 { 18 d[v]=d[u]+w; 19 if (!vs[v]) 20 { 21 vs[v]=true; 22 q.push(v); 23 } 24 } 25 } 26 } 27 }