[Python] Dijkstra || Bellman-Ford || Floyd-Warshall
Dijkstra\nTime: O(ElogV)\nSpace: O(V+E)\n\n- Single Source Shortest Path\n- Finds the shortest path from one node to all other nodes. \n- A greedy  algorithm th
**Dijkstra**\nTime: ```O(ElogV)```\nSpace: ```O(V+E)```\n\n- Single Source Shortest Path\n- Finds the shortest path from one node to all other nodes. \n- A greedy  algorithm that works by always exploring the shortest available path first. \n```\nclass Solution(object):\n\n    def networkDelayTime(self, times, N, K):\n        adj_list = self.get_adj_list(times, N)\n        heap = [(0, K)]\n        distance_from_k = {}\n        \n        while heap:\n            curr_dist, curr_node = heapq.heappop(heap)\n            distance_from_k[curr_node] = curr_dist\n            if len(distance_from_k) == N:\n                break\n            for neighbor, weight in adj_list[curr_node]:\n                if neighbor not in distance_from_k:\n                    heapq.heappush(heap, (curr_dist + weight, neighbor))\n                                       \n        return max(distance_from_k.values()) if len(distance_from_k) == N else -1\n        \n    def get_adj_list(self, times, N):\n        temp = {i:[] for i in range(1,N+1)}\n        for node1, node2, weight in times:\n            temp[node1].append((node2, weight))\n        return temp \n```\n\n**Bellman Ford**\nTime: ```O(VE)```\nSpace: ```O(V)```\n\n- Single Source Shortest Path \n- A Dynamic Programming algorithm that can handle negative edge weights\n```\n    def networkDelayTime(self, times, N, K):\n\t\tdistance = {i:float(\'inf\') for i in range(1, N+1)}\n\t\tdistance[K] = 0 \n\t\t\n\t\tfor _ in range(N-1):\n\t\t\tfor node1, node2, weight in times:\n\t\t\t\tif distance[node1] + weight < distance[node2]:\n\t\t\t\t\tdistance[node2] = distance[node1] + weight\n\t\treturn max(distance.values()) if max(distance.values()) != float(\'inf\') else -1 \n```\n\n**Floyd-Warshall**\nTime: ```O(n^3)```\nSpace: ```O(n^2)```\n\n- All Pairs Shortest Path\n- Finds the shortest path between all pairs of nodes\n```\n    def networkDelayTime(self, times, N, K):\n\t\t# Initial Matrix Setup\n        matrix = [[float(\'inf\') for _ in range(N)] for _ in range(N)]\n    \n        for node1, node2, weight in times:\n            matrix[node1-1][node2-1] = weight\n        \n        for i in range(len(matrix)):\n            matrix[i][i] = 0 \n         \n\t\t# Actual Iteration and Finding of Shortest Path\n        for k in range(N):\n            for node1 in range(N):\n                for node2 in range(N):\n                    matrix[node1][node2] = min(matrix[node1][node2], matrix[node1][k] + matrix[k][node2])\n        \n\t\treturn max(matrix[K-1]) if max(matrix[K-1]) != float(\'inf\') else -1\n```
[]