CF 題目集錦 PART 5 #266 div 2 E
阿新 • • 發佈:2019-01-06
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place:
-
either employee y became the boss of employee x (at
that, employee x
- or employee x gets a packet of documents and signs them; then he gives the packet to his boss. The boss signs the documents and gives them to his boss and so on (the last person to sign the documents sends them to the archive);
-
or comes a request of type "determine whether employee x
Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies.