Advertisement
999ms

Untitled

Mar 1st, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. vector<int> g[n];
  2. int depth[n];
  3. void dijkstra(int from){
  4. fill(depth,depth+n, inf);
  5. depth[0] = 0;
  6. priority_queue<pair<int,int> > q;
  7. q.push({0,from});
  8. while(q.size()){
  9. auto [nxtw, nxtv] = q.front();
  10. q.pop();
  11. if(depth[nxtv] < -nxtw) continue;
  12. for(int v : g[nxtv]){
  13. if(depth[nxtv] + 1 < depth[v]){
  14. depth[v] = depth[nxtv] + 1;
  15. q.push({-depth[v],v});
  16. }
  17. }
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement