Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

An undirected graph has the vertices E, G, I, L and the edges G–I, G–E, I–L, L–E. A walk may repeat vertices and edges. How many walks of length exactly 3 go from G to I?

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

Correct answer: A. 4

The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 4. Simple paths from G to I give only 2, and walks of length 2 give 0.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic