Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional

An undirected graph on 5 vertices has the edges D–E, D–J, D–T, E–H, E–J, E–T, H–T, J–T. How many simple paths (no repeated vertex) go from D to T? Paths are counted as vertex sequences, so each route is counted once.

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

Correct answer: C. 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