Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
A directed graph with no directed cycles has arcs u→v (weight) : F→S (3), F→N (0), F→C (8), G→X (2), G→C (4), S→X (3), N→X (1), N→C (6), X→C (1). Weights may be negative. What is the minimum total weight of a path from F to C that uses at most 2 arcs?
- A. 6
- B. 8
- C. 2
- D. 7
Correct answer: A. 6
Plain Bellman–Ford with k rounds (relaxing only through paths of length at most 2) gives 6. Ignoring the limit gives 2, and only paths of exactly 2 arcs give 6.
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 connected undirected graph has the vertices B, E, G, K, Q, R, S, V and the edges Q–K, K–B, K–G, K–S, G–V, G–R, G–E, S–E, R–E. Parallel…
- Grid with 4 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .GG G.G .G. ... Each step, which is a…
- A tree has vertices with values in brackets: P[-4], S[4], V[7], U[1], G[-4], D[1]. The edges are P–S, S–V, V–U, S–G, S–D. A path is any…
- 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 grid has 3 rows and 4 columns with these values (top to bottom): 6389 5169 6136 A path moves between side-adjacent cells (up, down, left…
- A directed acyclic graph has the vertices F, H, M, P, U, W and the arcs H→M, H→W, U→F, F→M, F→P, F→W, M→P, M→W. Two players alternately…