void spfa(int s){
memset(dist,0x3f,sizeof(dist));
memset(v,0,sizeof(v));
dist[s]=0;.
q.push(s);
v[s]=1;
while(!q.empty()){
int x=q.front();
q.pop();
v[x]=0;
for(int i=head[x];i;i=edge[i].nxt){
int y=edge[i].to;
if (dist[x]+edge[i].w<dist[y]){
dist[y]=dist[x]+edge[i].w;
if(v[y]==0){
q.push(y);
v[y]=1;
}
}
}
}
}
我有模板,但不会用