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.

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic