1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| struct edge{ int v,w; }; struct node{ int x,d; friend bool operator < (node tmp_x,node tmp_y){ return tmp_x.d>tmp_y.d; } }; vector<edge>e[100001]; int dis[100001],vis[100001]; priority_queue<node>q; void dijkstra(int n,int s){ memset(dis,0x3f,sizeof(dis)); while(!q.empty())q.pop(); q.push({s,0}); dis[s]=0; while(!q.empty()){ int now=q.top().x; q.pop(); if(!vis[now]){ vis[now]=1; for(auto ed:e[now]){ int v=ed.v; int w=ed.w; if(dis[v]>dis[now]+w){ dis[v]=dis[now]+w; q.push({v,dis[v]}); } } } } }
|