Data Structures & AlgorithmsHardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 60→27, 28→77, 77→32, 60→64, 32→60, 32→86, 86→30, 77→76. The root is at depth 0. How many nodes lie at depth exactly 3?

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

Correct answer: A. 2

Count the nodes whose depth is exactly 3, by computing each node's depth from the root. Off-by-one on the depth, or counting cumulatively, gives the trap values.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic