Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> dijkstra(int v,int n ,vector<vector<array<int,2>>>&g){
- vector<int>dis(n,INF);
- dis[v]=0;
- priority_queue<array<int,2>,vector<array<int,2>>,greater<array<int,2>> >pq;
- pq.push({0,v});
- while(!pq.empty()){
- int ver=pq.top()[1],dist=pq.top()[0];
- pq.pop();
- if(dis[ver]!=dist) continue;
- for(auto u:g[ver]){
- int to = u[0], weight = u[1];
- if(dis[to]>dis[ver]+weight){
- dis[to]=dis[ver]+weight;
- pq.push({dis[to],to});
- }
- }
- }
- return dis;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement