Data Structures & AlgorithmsVery hardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 10→26, 60→44, 10→42, 26→60, 45→92, 60→40, 49→85, 10→20, 43→15, 26→72, 43→14, 60→43, 10→45, 15→49. The root is at depth 0. How many nodes lie at depth exactly 4?

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

Correct answer: A. 2

Count the nodes whose depth is exactly 4, 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