Data Structures & AlgorithmsHardCodeforces Div 2 B · GATE CS
Directed graph on vertices 0 to 6; every edge costs 0 or 1: 3→0 (0), 2→0 (1), 2→4 (1), 6→2 (1), 1→5 (1), 2→6 (1), 6→1 (0), 3→1 (1), 1→4 (0), 6→5 (1), 0→1 (1), 0→5 (1), 0→3 (1), 1→3 (0), 3→2 (0), 5→1 (0). What is the minimum total cost of a path from 0 to 6, where a path's cost is the sum of its edge costs?
- A. 1
- B. unreachable
- C. 3
- D. 2
Correct answer: D. 2
A 0-1 BFS (or Dijkstra) gives cost 2. Counting hops gives 3, and forbidding the 0-cost edges gives unreachable; both are traps.
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 connected weighted graph on vertices 0 to 6 with edges (u–v (w)): 2–4 (8), 0–1 (4), 0–3 (11), 2–5 (4), 0–5 (3), 3–4 (1), 1–3…
- Undirected connected weighted graph on vertices 0 to 7 with edges (u–v (w)): 1–6 (5), 3–7 (7), 3–5 (6), 6–7 (10), 4–5 (9), 0–1 (11), 0–7…
- Undirected connected weighted graph on vertices 0 to 5 with edges (u–v (w)): 1–5 (9), 2–3 (9), 3–5 (5), 0–3 (11), 1–2 (11), 2–4 (2), 3–4…
- Undirected connected weighted graph on vertices 0 to 6 with edges (u–v (w)): 3–4 (11), 0–6 (11), 1–4 (7), 2–5 (2), 4–6 (10), 1–6 (1), 0–2…
- Undirected connected weighted graph on vertices 0 to 5 with edges (u–v (w)): 2–5 (11), 0–4 (12), 1–3 (8), 0–1 (9), 2–3 (2), 2–4 (3), 0–5…
- Undirected connected weighted graph on vertices 0 to 7 with edges (u–v (w)): 6–7 (6), 0–4 (10), 1–5 (1), 3–7 (3), 3–4 (7), 1–6 (6), 2–4…