1 priority_queue< pair<ll,ll> >q; 2 void SPFA(ll top) 3 { 4 memset(bian,0,sizeof(bian)); 5 dis[top]=0;q.push(make_pair(0,top));bian[top]=1; 6 while(!q.empty()) 7 { 8 ll x=q.top().second;q.pop(); 9 for(ll i=head[x];i;i=e[i].n) 10 { 11 ll to=e[i].to; 12 if(dis[to]>dis[x]+e[i].w) 13 { 14 dis[to]=dis[x]+e[i].w; 15 if(bian[to]==0) 16 { 17 q.push(make_pair(-dis[to],to)); 18 bian[to]=1; 19 } 20 } 21 } 22 } 23 }