Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2 E
Directed graph on vertices 0 to 6 with positive weights (u→v (w)): 0→4 (1), 4→2 (1), 5→2 (4), 6→4 (2), 1→2 (1), 1→0 (2), 1→6 (1), 4→6 (4), 2→6 (3), 6→5 (3), 1→3 (1), 6→2 (2), 0→5 (2), 2→0 (4), 6→0 (4), 2→1 (4), 3→2 (3), 5→0 (4), 3→4 (2), 1→5 (3). The shortest distance from 0 to 6 is 5. How many edges e have this property: adding 1 to the weight of e, and changing nothing else, makes the shortest distance from 0 to 6 strictly larger?
- A. 1
- B. 4
- C. 2
- D. 20
Correct answer: A. 1
An edge is critical exactly when it lies on every shortest route; recomputing distances after each +1 gives 1. Counting edges on some shortest route (4) overcounts alternatives, and the edges of one route (2) is a different quantity.
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 5 with positive weights (u→v (w)): 0→4 (1), 0→1 (4), 0→3 (3), 1→5 (2), 4→1 (3), 2→0 (1), 0→2 (2), 4→2 (2)…
- Directed graph on vertices 0 to 4 with positive weights (u→v (w)): 0→4 (4), 2→4 (1), 1→2 (2), 1→3 (1), 0→3 (2), 0→1 (1), 1→0 (3), 2→1 (2)…
- Directed graph on vertices 0 to 5 with positive weights (u→v (w)): 1→2 (4), 3→5 (4), 2→0 (2), 4→5 (3), 5→4 (3), 4→2 (4), 5→1 (1), 0→3 (4)…
- Simple undirected graph on vertices 0 to 4 with edges: 1–2, 0–1, 0–3, 0–2, 2–4, 3–4. How many simple cycles does it contain? A cycle has…
- Simple undirected graph on vertices 0 to 5 with edges: 0–2, 1–5, 2–5, 1–4, 1–3, 0–1, 3–5, 1–2, 0–5. How many simple cycles does it…
- Simple undirected graph on vertices 0 to 4 with edges: 0–4, 0–2, 1–4, 2–4, 1–2, 0–1, 2–3. How many simple cycles does it contain? A cycle…