Question DSA-GRAPH-0062
HardWhat is the output of this code?
def bellman(n, edges, s):
d = [float("inf")] * n; d[s] = 0
for _ in range(n - 1):
for u, v, w in edges:
if d[u] + w < d[v]: d[v] = d[u] + w
neg = any(d[u] + w < d[v] for u, v, w in edges)
return d, neg
print(bellman(4, [(0, 1, 4), (0, 2, 5), (1, 2, -3), (2, 3, 2), (1, 3, 6)], 0))
- A.
([0, 4, 5, 7], False)
- B.
([0, 1, 4, 3], False)
- C.
Sign up free to see the answer and a step-by-step explanation.