Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
Bellman–Ford is run from source U on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: K→U (4), K→Z (4), Z→K (1), Z→U (9), R→K (6), Z→R (3), U→R (5). 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. 7
- B. 5
- C. 3
- D. 4
Correct answer: D. 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
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A tree has vertices with weights in brackets: D[15], C[15], R[7], L[9], S[1], Z[3], B[13], H[13], F[6]. The edges are D–C, D–R, R–L, D–S…
- A tree on the vertices C, F, H, L, P, V, W has the arcs V→P, F→P, P→C, F→H, V→L, W→H (each undirected edge is directed as shown). You may…
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. RRLL URUU RRUD From a cell you may move…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 18. Two sequences of steps…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3, 4} and s ≤ the pile size. The player who…