✅C++ || CLEAN && Easy to Understand CODE || Dijkstra's Algo
\n\nLogic - > No Logic! Strightforward question, just Apply Dijkstra\'s or Bellman Ford and you are good to go!\n\nT-> O(E log V) && S->O(V)\n\n\n\tclass Soluti
![image](https://assets.leetcode.com/users/images/508675ef-01a6-40de-a20d-16519385915c_1672412279.7534595.png)\n\n***Logic - > No Logic! Strightforward question, just Apply Dijkstra\'s or Bellman Ford and you are good to go!***\n\n**T-> O(E log V) && S->O(V)**\n\n\n\tclass Solution {\n\t\tpublic:\n\t\t\tint networkDelayTime(vector<vector<int>>& times, int n, int k) {\n\t\t\t\tvector<pair<int,int>> adj[n + 1];\n\t\t\t\tvector<int> dis(n + 1,1e9);\n\t\t\t\tpriority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n\n\t\t\t\tfor(auto i : times){\n\t\t\t\t\tint u = i[0];\n\t\t\t\t\tint v = i[1];\n\t\t\t\t\tint wt = i[2];\n\t\t\t\t\tadj[u].push_back({v,wt});\n\t\t\t\t}\n\n\t\t\t\tdis[0]=-1e9;\n\t\t\t\tdis[k] = 0;\n\t\t\t\tpq.push({0,k});\n\n\t\t\t\twhile(!pq.empty()){\n\t\t\t\t\tint u = pq.top().second;\n\t\t\t\t\tint d = pq.top().first;\n\t\t\t\t\tpq.pop();\n\n\t\t\t\t\tfor(auto node : adj[u]){\n\t\t\t\t\t\tint v = node.first;\n\t\t\t\t\t\tint wt = node.second;\n\t\t\t\t\t\tif(d + wt < dis[v]){\n\t\t\t\t\t\t\tdis[v] = d + wt;\n\t\t\t\t\t\t\tpq.push({dis[v],v});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor(auto i : dis){\n\t\t\t\t\tif(i==1e9) return -1;\n\t\t\t\t}\n\n\t\t\t\treturn *max_element(dis.begin(),dis.end());\n\t\t\t}\n\t\t};
['C', 'Heap (Priority Queue)', 'C++']