Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→C (9), A→G (5), B→F (3), C→D (3), D→E (8). What is the largest total weight of any directed path (one or more edges) in this graph?

  1. A. 20
  2. B. 9
  3. C. 3
  4. D. 28

Correct answer: A. 20

A DP over vertices in topological order gives a heaviest path of weight 20. Counting the edges of that path, or summing every weight, gives other numbers.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic