Advertisement
yungyao

dijkstra

Nov 13th, 2021
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1.     REP1(i,n) dis[i] = inf;
  2.     dis[1] = 1;
  3.     priority_queue <pii,vector<pii>,greater<pii>> pq;
  4.     pq.push(mkp(0,1));
  5.  
  6.     while (!pq.empty()){
  7.         auto [d,x] = pq.top(); pq.pop();
  8.  
  9.         if (d > dis[x]) continue;
  10.  
  11.         for (auto [i,w]:adj[x]){
  12.             if (d + w < dis[i]){
  13.                 dis[i] = d + w;
  14.                 pq.push(mkp(dis[i],i));
  15.             }
  16.         }
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement