Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void dijkstra(int src , vector < int >& dis, int n)
- {
- for(int i = 1 ; i <= n ; i++) dis[i] = MAX;
- priority_queue < pair < int , int > > tempo;
- tempo.push({0 , src});
- while(!tempo.empty()){
- pair < int , int > p = tempo.top();
- tempo.pop();
- int node = p.second;
- if(-p.first > dis[node]) continue;
- for(auto adj:edg[node]){
- int a = adj.first , w = adj.second;
- int val = dis[node] + w;
- if(val < dis[a]){
- dis[a] = val;
- tempo.push({-val , a});
- }
- }
- }
- } /// O(m * log(m) ) ; m = number of edges
Advertisement
Add Comment
Please, Sign In to add comment