Using Dijkstra Algorithm, [C++]
Implementation\n\nUsing Dijkstra Algorithm\nTime Complexity = O(N + ElogN)\nSpace Complexity = (O(N+E) + O(N) + O(N)) => O(N+E)\nWhere N is the nunber of vertic
Implementation\n\n**Using Dijkstra Algorithm\nTime Complexity = O(N + ElogN)\nSpace Complexity = (O(N+E) + O(N) + O(N)) => O(N+E)\nWhere N is the nunber of vertices in the graph and E is the number of edges**\n\n```\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n        \n        vector<pair<int, int>> graph[n+1];\n        \n        for(auto time : times){\n            graph[time[0]].push_back({time[1], time[2]});\n        }\n        \n        vector<int> distance(n+1, INT_MAX);        \n        distance[k] = 0;\n\t\t\n\t\t// to create min heap we need to take pass these 3 parameters\n        // data type, vector type, comparison\n        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n        \n        pq.push({0, k});\n        \n        while(!pq.empty()){\n            int dis = pq.top().first;\n            int node = pq.top().second;\n            pq.pop();\n            \n            for(auto adjacentNode : graph[node]){\n                int destinationNode = adjacentNode.first;\n                int weight = adjacentNode.second;\n                \n                if(dis + weight < distance[destinationNode]){\n                    distance[destinationNode] = dis + weight;\n                    pq.push({dis + weight, destinationNode});\n                }\n            }\n        }\n        \n        int res = INT_MIN;\n        for(int i = 1; i < distance.size(); i++){\n            res = max(res, distance[i]);\n        }\n        \n        return (res == INT_MAX) ? -1 : res;\n    }\n};\n```\nIf you find any issue in understanding the solution then comment below, will try to help you.\nIf you found my solution useful.\nSo **please do upvote and encourage me** to document all leetcode problems\uD83D\uDE03\nHappy Coding :)
['Graph', 'C', 'Heap (Priority Queue)', 'Shortest Path']