Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
Directed acyclic graph on vertices A, B, C, D, E, F, G, H (edges go from earlier to later letters) with weights A→C (4), A→E (3), A→F (2), A→G (1), B→F (2), C→D (3), C→E (3), C→G (3), D→E (2), D→F (4), D→G (2), D→H (4), F→H (1), G→H (4). Count the number of DIFFERENT paths from A to H whose total weight is the minimum possible.
- A. 6
- B. 3
- C. 12
- D. 2
Correct answer: D. 2
The shortest distance is 12 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
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–G (1), B–F (1), B–G (1), C–E (1), C–F (1), C–G (1), D–E (1)…
- Directed weighted graph on vertices E, C, A, B, D (source E, target D) with edges: E→C (2); E→A (3); A→C (-3); C→D (3); A→D (3); E→D (18)…
- A trie keeps a counter at each node, and every word of the list W = ['acb', 'c', 'bcb', 'c', 'bc', 'a', 'aac'] is inserted once per…
- On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (3, 5) and must reach (5, 0) (as (row, column)). A knight…
- Dictionary D = {bem, cle, gcc, icd, imb, lbg, lcp, lri, ois, opg, scc, scp} (all words have 3 letters). Starting from the word 'lcd', a…
- Directed weighted graph on vertices A, B, C, D, E with edges E→C (-3); A→D (-4); A→B (-2); D→B (0); B→C (-2); A→E (-1); E→D (0); B→E (-4)…