K-step Tree (treeancestor)

59 teams scored 3688 points on this task, for a maximum score of 100, an average score of 63 and a median score of 51.

Highlights

  1. Galileo Ferraris, Molfetta is the institute with the most points (200).
  2. Lombardia is the region with the most points (811).

Statement

The final round of IIOT is approaching and after solving so many tree problems during the previous edition of the contest, you start to wonder what the next tree problem is going to be. Your instincts were spot-on, finally here is a tree problem for you to solve! You are given a tree graph with N nodes, rooted at vertex 0. We define the K-th ancestor of a vertex as the node we reach if we move K steps up the tree, in the direction of the root. If we reach the root before doing K steps, then we say that the K-th ancestor does not exist. For a fixed integer K, your task is to find the K-th ancestor of each node in the tree, or report that it doesn't exist. Pay attention to the unusual memory limit!