# O(V*E)
dist = [inf] * n
dist[src] = 0
for i in range(n-1):
changed = False
for u, v, d in edges:
if dist[u] + d < dist[v]:
dist[v] = dist[u] + d
changed = True
if not changed:
break
Problems
787. Cheapest Flights Within K Stops
- https://leetcode.com/problems/cheapest-flights-within-k-stops
- Apply bellman ford for
k+1
iterations