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