Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Directed acyclic graph on vertices A, B, C, D, E, F, G (edges go from earlier to later letters) with weights A→C (4), A→F (1), B→D (2), B→G (3), C→D (3), C→E (2), D→F (1), D→G (3), E→F (1), F→G (4). Count the number of DIFFERENT paths from A to G whose total weight is the minimum possible.
- A. 2
- B. 3
- C. 4
- D. 11
Correct answer: A. 2
The shortest distance is 11 and 2 distinct paths achieve it, found by DP that adds counts only on ties. Counting all paths, or reporting the distance, 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 A, B, C, D, E, F with edges F→D, C→F, A→D, A→C, F→E, F→C, B→E (no weights). What is the number of vertices in…
- Undirected weighted graph on vertices A, B, C, D with edges A–B (3), A–C (2), A–D (1), B–C (1), B–D (2). How many distinct minimum…
- Weighted tree on vertices 0 to 8 with edges 0–1 (6), 1–2 (7), 0–3 (8), 0–4 (1), 0–5 (1), 5–6 (6), 2–7 (2), 4–8 (2). What is the largest…
- Array A = [25, 23, 7, 3, 1] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 5?
- Keys are inserted in the order 51 18 15 34 11 into an empty binary search tree. Then the key 18 (which has two children) is deleted by…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–C (1), B–D (1), B–E (1), B–G (1), C–D (1), D–F (1), D–G (1)…