Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

An undirected graph on 7 vertices has the edges J–P, J–O, J–U, P–O, P–B, P–U, O–S, O–A, O–U, A–U. How many simple paths (no repeated vertex) go from J to U? Paths are counted as vertex sequences, so each route is counted once.

  1. A. 10
  2. B. 1
  3. C. 3
  4. D. 7

Correct answer: D. 7

A DFS that extends the path through unvisited neighbours enumerates every simple route, giving 7. Counting only the shortest routes gives 1, which is a much smaller set.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic