Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
Directed graph on vertices 0 to 7 with non-negative weights (u→v (w)): 2→3 (3), 2→0 (4), 4→5 (1), 1→2 (2), 2→1 (15), 0→1 (2), 0→3 (11), 1→5 (11), 6→7 (1), 0→2 (8), 1→7 (17), 2→4 (17), 5→6 (3), 3→4 (3). What is the minimum total weight of a path from 0 to 7 that uses AT MOST 3 edges?
- A. 15
- B. 17
- C. 19
- D. 40
Correct answer: C. 19
Dynamic programming over the number of edges gives 19. The unconstrained shortest path (15) uses too many edges, allowing 4 edges gives 17, and insisting on exactly 3 edges gives 40.
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 7 with non-negative weights (u→v (w)): 4→5 (1), 1→7 (20), 2→3 (2), 0→1 (2), 4→1 (18), 6→7 (3), 3→4 (3)…
- Directed graph on vertices 0 to 6 with non-negative weights (u→v (w)): 5→6 (2), 2→3 (1), 3→4 (3), 3→6 (11), 0→1 (1), 1→2 (1), 4→5 (3), 5→3…
- Directed graph on vertices 0 to 7 with non-negative weights (u→v (w)): 6→7 (1), 4→1 (11), 0→1 (1), 2→3 (3), 1→4 (16), 4→5 (2), 1→7 (16)…
- Simple undirected graph on vertices 0 to 6 with edges: 1–4, 3–4, 4–6, 0–2, 4–5, 0–3, 2–4, 2–3, 1–5, 2–6. What is its chromatic number, the…
- Simple undirected graph on vertices 0 to 6 with edges: 1–4, 4–6, 3–5, 2–3, 5–6, 4–5, 0–6, 0–4, 1–5, 2–4. What is its chromatic number, the…
- Simple undirected graph on vertices 0 to 6 with edges: 2–4, 1–5, 4–5, 2–5, 5–6, 0–6, 4–6, 3–4, 0–5. What is its chromatic number, the…