Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

The directed acyclic graph has the vertices C, F, G, K, N, T, W and the arcs C→F, W→C, G→N, G→K, N→F, K→F, T→W, W→F, T→F, G→T, K→C, T→K. How many distinct directed paths go from G to F? A path is a sequence of consecutive arcs; a single arc counts as a path.

  1. A. 3
  2. B. 8
  3. C. 4
  4. D. 6

Correct answer: B. 8

Count with ways[x] = sum of ways[y] over arcs y→x, starting at ways[G] = 1 and processing vertices in a topological order. This gives 8 paths; using only paths of at most two arcs would give 3.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic