展开全部
可以使32313133353236313431303231363533e78988e69d8331333365633836用最短路int spfa(){
dl[head=tail=1]=sor;
for (int i=1;i<=n+2;i++) dis[i]=1e9;
b[sor]=1;
dis[sor]=0;
while (head<=tail){
for (int p=nd[dl[head]];p!=-1;p=sid[p].next)
if ((dis[sid[p].des]>dis[dl[head]]+sid[p].cos)){
path[sid[p].des]=p;
if (b[sid[p].des]==0){
dl[++tail]=sid[p].des;
}
dis[sid[p].des]=dis[dl[head]]+sid[p].cos;
}
b[dl[head++]]=0;
}
if (dis[tar]==1e9) return(0);else return(1);
}