Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: Count the walks of length 3 on the path graph P4 (vertices 1–4, edges 1-2, 2-3, 3-4) that start and end at the same vertex. Walks may revisit vertices.

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

Correct answer: A. 0

Odd-length closed walks in a bipartite graph are impossible, since each step switches the colour class. The count is therefore zero, and any nonzero result would indicate an error in the walk counting.

More Coding Interview Problems questions

Exams that ask this topic