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→B (3), A→D (4), A→E (4), A→F (4), B→C (3), B→E (2), C→D (3), C→F (3), C→G (2), D→G (4), E→F (1), E→G (3). Count the number of DIFFERENT paths from A to G whose total weight is the minimum possible.

  1. A. 3
  2. B. 5
  3. C. 2
  4. D. 9

Correct answer: C. 2

The shortest distance is 9 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