Data Structures & AlgorithmsHardCodeforces Div 2 C
Directed graph on vertices 0 to 5 with positive weights (u→v (w)): 1→5 (2), 1→4 (2), 4→5 (3), 1→2 (2), 0→1 (2), 4→3 (1), 4→0 (2), 3→4 (3), 2→4 (2), 3→2 (1), 0→2 (3), 0→4 (1), 5→1 (1), 1→3 (3), 4→1 (1), 2→0 (3), 3→5 (2). How many different paths from 0 to 5 have the minimum possible total weight? Two paths are different if their vertex sequences differ.
- A. 4
- B. 2
- C. 1
- D. 3
Correct answer: A. 4
The minimum weight is 4. Propagating path counts along tight edges (d[u] + w = d[v]) gives 4. Keeping a single parent gives 1, and counting shortest-hop routes (2) answers a different question.
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
- Directed graph on vertices 0 to 6 with positive weights (u→v (w)): 2→1 (2), 3→6 (3), 6→3 (3), 5→1 (2), 4→1 (3), 6→5 (2), 2→3 (1), 4→6 (1)…
- Directed graph on vertices 0 to 5 with positive weights (u→v (w)): 1→0 (2), 1→4 (2), 3→4 (3), 5→0 (1), 4→1 (3), 1→3 (1), 0→4 (3), 1→5 (2)…
- Directed graph on vertices 0 to 6 with positive weights (u→v (w)): 1→6 (3), 1→0 (3), 0→4 (3), 3→0 (1), 1→3 (1), 4→0 (1), 0→2 (3), 2→0 (2)…
- Directed graph on vertices 0 to 6 with positive weights (u→v (w)): 2→4 (1), 1→4 (2), 6→4 (3), 3→4 (2), 3→0 (2), 3→1 (3), 4→5 (2), 1→2 (1)…
- Directed graph on vertices 0 to 5 with positive weights (u→v (w)): 0→1 (2), 3→0 (2), 0→2 (3), 1→5 (3), 5→1 (3), 4→5 (1), 4→2 (2), 2→0 (1)…
- Undirected weighted graph on vertices A to G with edges listed as: D–F (6), B–C (5), D–E (3), A–B (6), A–F (5), D–G (3), C–G (6), A–G (5)…