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.

  1. A. 6
  2. B. 3
  3. C. 12
  4. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic