DFS / BFS / Dijkstra / Bellman Ford / Floyd Warshall easy to understand [Python]
```\nclass Solution:\n    \n    def BellmanFord(self, times, N, K):\n        \n        # Bellman Ford\n        cost = {i:float(\'inf\') for i in range(1, N+1)}\
```\nclass Solution:\n    \n    def BellmanFord(self, times, N, K):\n        \n        # Bellman Ford\n        cost = {i:float(\'inf\') for i in range(1, N+1)}\n        cost[K] = 0\n        for i in range(N-1):\n            update = False\n            for u, v, c in times:\n                if cost[u]+c<cost[v]:\n                    update = True\n                    cost[v] = cost[u]+c\n            if not update:\n                break\n        \n        ans = max(cost.values())\n        return ans if ans!=float(\'inf\') else -1\n                \n            \n      \n    \n    def Dijkstra(self, times, N, K):\n        g = collections.defaultdict(list)   # [(node, cost)]\n        for u, v, c in times:\n            g[u].append((v, c))\n        \n        cost = {i:float(\'inf\') for i in range(1, N+1)}\n        cost[K] = 0\n        from queue import PriorityQueue\n        pq = PriorityQueue()\n        pq.put((0, K))\n        \n        while not pq.empty():\n            curr_cost, curr_node = pq.get()\n            \n            for nei, c in g[curr_node]:\n                if curr_cost+c<cost[nei]:\n                    cost[nei] = curr_cost+c\n                    pq.put((cost[nei], nei))\n        \n        ans = max(cost.values())\n        return ans if ans!=float(\'inf\') else -1\n    \n    \n    \n            \n                \n    def DFS(self, times, n, k):\n        cost = {i:float(\'inf\') for i in range(1, N+1)}\n        g = collections.defaultdict(list)\n        for u, v, c in times:\n            g[u].append((v, c))\n        \n        def DFS(curr, curr_cost):\n            if curr_cost<cost[curr]:\n                cost[curr] = curr_cost\n                for nei, c in g[curr]:\n                    DFS(nei, curr_cost+c)\n        \n        DFS(K, 0)\n        ans = max(cost.values())\n        return ans if ans!=float(\'inf\') else -1\n    \n            \n            \n        \n        \n        \n        \n    \n    def BFS(self, times, N, K):\n        g = collections.defaultdict(list)\n        for u, v, c in times:\n            g[u].append((v, c))\n        \n        cost = {i:float(\'inf\') for i in range(1, N+1)}\n        cost[K] = 0\n        curr = collections.deque()\n        curr.append((K, 0))\n        \n        while curr:\n            curr_node, curr_cost = curr.popleft()\n            for nei, c in g[curr_node]:\n                if curr_cost+c < cost[nei]:\n                    cost[nei] = curr_cost+c\n                    curr.append((nei, curr_cost+c))\n        \n        ans = max(cost.values())\n        return ans if ans!=float(\'inf\') else -1\n\n    def FloydWarshall(self, times, N, K):\n        # APSP\n        cost = {}\n        for i in range(1, N+1):\n            for j in range(1, N+1):\n                if i==j:\n                    cost[(i, j)] = 0\n                else:\n                    cost[(i, j)] = float(\'inf\')\n        \n        for u,v,c in times:\n            cost[(u, v)] = c\n            \n        for k in range(1, N+1):\n            for i in range(1, N+1):\n                for j in range(1, N+1):\n                    cost[(i, j)] = min(cost[(i, j)], cost[(i, k)]+cost[(k, j)])\n        \n        \n        ans = float(\'-inf\')\n        for i in range(1, N+1):\n            ans = max(ans, cost[(K, i)])\n\n        return ans if ans!=float(\'inf\') else -1\n\n    \n
['Depth-First Search', 'Breadth-First Search', 'Python3']