#C2090. Depth of the Root

    ID: 45368 Type: Default 1000ms 256MiB

Depth of the Root

Depth of the Root

You are given a binary tree that initially contains only the root node numbered 1. The tree is modified through a series of operations. Each operation is one of the following:

  • ADD P C: Add a new node C as a child of node P.
  • REMOVE P: Remove the subtree rooted at node P (except the root which is never removed).

After each operation, you are required to determine the depth of the root node. Recall that the depth of the root is always 0 (i.e. \(0\)). Thus, regardless of the modifications to the tree, the answer remains 0 after each operation.

Note: Although the operations modify the tree, the depth of the root node (node 1) never changes. This problem is designed to test your ability to process input and output as specified.

inputFormat

The first line contains two integers n and q, representing the total number of nodes and the number of operations, respectively.

Each of the next q lines contains an operation in one of the following formats:

  • ADD P C — Add node C as a child of node P.
  • REMOVE P — Remove the subtree rooted at node P.

outputFormat

Output q lines. Each line should contain a single integer representing the depth of the root node (node 1) after each corresponding operation.

Since the root node is never removed and always remains at the top, the output for every operation will be 0.

## sample
5 5
ADD 1 2
ADD 1 3
REMOVE 2
ADD 3 4
REMOVE 3
0

0 0 0 0

</p>