Data Structures & AlgorithmsModerateGATE CS · ICPC regional
A directed graph with no directed cycles has arcs u→v (weight) : U→J (2), U→K (4), J→S (0), J→K (4), S→K (-1), P→K (3). Weights may be negative. What is the minimum total weight of a path from U to K that uses at most 2 arcs?
- A. 5
- B. 4
- C. 1
- D. 6
Correct answer: B. 4
Plain Bellman–Ford with k rounds (relaxing only through paths of length at most 2) gives 4. Ignoring the limit gives 1, 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 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 directed graph has the vertices A, E, F, M, N, R and the arcs R→F, R→M, A→M, M→R, M→A, E→F, E→N. How many strongly connected components…
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→2 (1), 1→3 (11), 1→4 (12), 2→1 (12), 2→3 (2), 2→4 (8), 3→1 (7), 3→2…
- Two unmarked jugs hold 6 litres and 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- 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 B, E, H, I, Q, R, U, V and the edges V–I, I–H, H–R, H–U, R–B, I–E, U–Q. A centroid is a vertex whose removal…