Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
A directed graph with no directed cycles has arcs u→v (weight) : K→Q (2), K→N (-3), K→I (8), J→L (3), J→I (8), Q→N (7), Q→L (6), N→L (0), L→I (-1). Weights may be negative. What is the minimum total weight of a path from K to I that uses at most 2 arcs?
- A. -4
- B. 8
- C. -3
- D. 7
Correct answer: B. 8
Within 2 arcs, K reaches I only by the direct arc (8); no 2-arc route ends at I. K→N→L→I = −4 needs 3 arcs, −3 is the distance to L, and 7 is the 3-arc route K→Q→L→I.
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 directed graph has the vertices A, D, J, N, P, V and the arcs N→V, N→P, N→A, V→A, D→A, P→A, A→V, A→D, A→J. How many strongly connected…
- Bellman–Ford is run from source M on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: G→D…
- A grid has 5 rows and 6 columns (top to bottom; '.' open, '#' blocked): ...... .##.#. ...... ....#. ...... You may only move right or…
- A tree has the vertices B, D, E, G, J, O, S, W and the edges S–J, J–D, J–B, B–O, S–G, D–W, G–E. A set D dominates the tree if every vertex…
- 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 the vertices A, D, E, G, I, L, P, V, W and the edges L–G, L–W, W–P, W–A, A–E, P–D, P–I, L–V. A centroid is a vertex whose…