Dijkstra's Algorithm || Simple C++ Solution ||
Code\n\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n        vector<vector<pair<int,int>>> adj(n+1,vector<pa
# Code\n```\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n        vector<vector<pair<int,int>>> adj(n+1,vector<pair<int,int>>{} );\n        for(auto x:times){\n            adj[x[0]].push_back({x[1],x[2]});\n        }\n\n        vector<int> dist(n+1,1e9);\n        dist[k]=0;\n        priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;\n        pq.push({0,k});\n\n        while(!pq.empty()){\n            int node=pq.top().second;\n            int dis=pq.top().first;\n            pq.pop();\n\n            for(auto x:adj[node]){\n                int adjNode=x.first;\n                int adjDist=x.second;\n                if(dis+adjDist < dist[adjNode]){\n                    dist[adjNode]=dis+adjDist;\n                    pq.push({adjDist+dis,adjNode});\n                }\n            }\n        }\n        int ans=-1;\n        for(int i=1;i<=n;i++){\n            ans=max(ans,dist[i]);\n        }\n        if(ans==1e9){return -1;}\n        return ans;\n    }\n};\n```
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'C++']