GATE Computer ScienceHardGATE CS (PYQ pattern)

A DAG has edges s→a, s→b, a→b, a→c, a→d, b→c, b→d, c→d, c→e, c→f, d→e, d→f, e→f, e→t, f→t. How many s–t paths pass through exactly one of the vertices c and d?

  1. A. 27
  2. B. 18
  3. C. 9
  4. D. 12

Correct answer: B. 18

Every s–t path passes through c or d. There are 27 s–t paths in total; the 9 paths that use the edge c→d visit both. So 27 − 9 = 18 visit exactly one. Forgetting the edge c→d gives 27 by double counting.

More Algorithms questions

Exams that ask this topic