最短路
作者:互联网
void dijkstra(int s) { for(int i=1;i<=n;i++) dis[i]=inf; dis[s]=0; priority_queue<nod> q; q.push((nod){s,0}); while(!q.empty()) { nod data=q.top(); q.pop(); int u=data.u; if(data.d!=dis[u]) continue; for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; if(dis[u]+e[i].w<dis[v]) { dis[v]=dis[u]+e[i].w; q.push((nod){v,dis[v]}); } } } }
标签:head,int,短路,nod,data,top,dis 来源: https://www.cnblogs.com/x176/p/15962770.html