Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> g[n];
- int depth[n];
- void dijkstra(int from){
- fill(depth,depth+n, inf);
- depth[0] = 0;
- priority_queue<pair<int,int> > q;
- q.push({0,from});
- while(q.size()){
- auto [nxtw, nxtv] = q.front();
- q.pop();
- if(depth[nxtv] < -nxtw) continue;
- for(int v : g[nxtv]){
- if(depth[nxtv] + 1 < depth[v]){
- depth[v] = depth[nxtv] + 1;
- q.push({-depth[v],v});
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement