CF342E Xenia and Tree

Description

Xenia the programmer has a tree consisting of $ n $ nodes. We will consider the tree nodes indexed from 1 to $ n $ . We will also consider the first node to be initially painted red, and the other nodes — to be painted blue. The distance between two tree nodes $ v $ and $ u $ is the number of edges in the shortest path between $ v $ and $ u $ . Xenia needs to learn how to quickly execute queries of two types: 1. paint a specified blue node in red; 2. calculate which red node is the closest to the given one and print the shortest distance to the closest red node. Your task is to write a program which will execute the described queries.

Input Format

N/A

Output Format

N/A