int dist[MAXN]; bool vis[MAXN]; priority_queue<pair<int ,int > >dd; void dij(){ memset(vis,0,sizeof(vis)); memset(dist,0x7f,sizeof(dist)); dist[1]=0; dd.push(make_pair(0,1)); while(!dd.empty()){ int ltop=dd.top().second;dd.pop(); // cout<<ltop<<endl; if(vis[ltop])continue; vis[ltop]=1; int base=dist[ltop]; for(int i=head[ltop];i;i=bl[i].nt){ if(base+bl[i].w>=dist[bl[i].to])continue; dist[bl[i].to]=base+bl[i].w; dd.push(make_pair(-dist[bl[i].to],bl[i].to)); } } }