C++ || Dijkstra's Algorithm  || priority_queue || Time:-O(NlogN) || space:-O(N) + O(N)
Time :- O((N+E)*logN) =O(NlogN)\nSpace:-O(N) {for dist arrays } + O(N) {for priority_queue}\n\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector
*Time* :- O((N+E)*logN) =O(NlogN)\nSpace:-O(N) {for dist arrays } + O(N) {for priority_queue}\n```\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n        int m=times.size();\n        vector<pair<int,int>>graph[n+1];\n        for(int i=0;i<m;i++)\n        {\n            graph[times[i][0]].push_back({times[i][1],times[i][2]});\n        }\n        // Dijkstra algorithm begins from here...\n        priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq; \n        vector<int> disto(n+1,INT_MAX); // (dis,from)\n        disto[k]=0;\n        pq.push({0,k});\n        \n        while(!pq.empty())\n        {\n            int dist=pq.top().first; // dis\n            int prev=pq.top().second; // node\n            pq.pop();\n            \n            vector<pair<int,int>>::iterator it;\n            for(auto it:graph[prev])\n            {\n                int next=it.first;  // next adjcent node  \n                int nextdist=it.second; // distance b/w the nodes\n                \n                if(disto[next] > disto[prev]+nextdist)\n                {\n                    disto[next]=disto[prev]+nextdist; // next dist = prev dist + weight of edge \n                    pq.push({disto[next],next}); // (dist,node)\n                }\n            }\n        }\n        int res=0;\n        for(int i=1;i<disto.size();i++)\n        {\n            res=max(res,disto[i]);\n        }\n        if(res==INT_MAX)\n        {\n            return -1;\n        }\n        else\n        {\n            return res;\n        }\n    }\n};\n```
[]