Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
Bellman–Ford is run from source O on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: L→O (6), O→L (6), M→O (7), L→M (6), L→Y (5), M→L (2), M→Y (8), Y→O (2), O→M (2). One pass relaxes every arc once, in the listed order. Passes are repeated until a complete pass changes no distance. Counting the final pass that changes nothing, how many passes run in total?
- A. 9
- B. 4
- C. 5
- D. 3
Correct answer: B. 4
The last pass changes no distance, so it is counted; the passes before it changed something, 3 of them. The bound n − 1 = 3 counts only the passes needed in the worst case.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Cities C, F, G, N, Q, X are joined by roads with these travel costs: C–Q 20, C–X 13, C–N 2, C–F 11, C–G 6, Q–X 8, Q–N 15, Q–F 13, Q–G 12…
- An undirected graph has the vertices J, M, N, Q, R, S, W and the edges R–N, M–Q, Q–J, Q–W, M–S, M–R, Q–R, Q–S, M–J, R–S. How many simple…
- A connected undirected graph has the vertices B, D, I, N, O, P, Z and the edges I–P, I–B, I–Z, I–N, P–N, P–O, B–D, Z–N. How many bridges…
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): U–O (17), F–O (26), O–P (18), U–V (10), F–P…
- A directed weighted graph has the arcs u→v (weight): X→L (9), X→K (15), L→X (11), L→O (3), L→K (1), L→M (15), O→X (11), O→L (5), O→M (7)…
- The directed acyclic graph has the vertices A, Q, T, V, W, Z and the arcs A→T, Z→Q, A→Q, W→T, Q→T, V→T, Z→V, A→V, V→Q. How many distinct…