The United Nations Regional Development Agency (UNRDA) has a very well defined
organizational structure. It employs a total of
We say that an employee
Unfortunately, the United Nations Bureau of Investigations (UNBI) recently received a number of
complaints that the UNRDA has an imbalanced organizational structure that favors some regions
of the world more than others. In order to investigate the accusations, the UNBI would like to
build a computer system that would be given the supervision structure of the UNRDA and would
then be able to answer queries of the form: given two different regions
Task
Write a program that, given the home regions of all of the agency's employees, as well as data on who is supervised by whom, interactively answers queries as described above.
Constraints
Input Specification
Your program must read from standard input the following data:
- The first line contains the integers
, and , in order, separated by single spaces. - The next
lines describe the employees of the agency in order of seniority. The th of these lines describes employee number . The first of these lines (i.e., the one describing the Chair) contains a single integer: the home region of the Chair. Each of the other lines contains two integers separated by a single space: employee 's supervisor , and employee 's home region .
Interaction
After reading the input data, your program must start alternately reading queries from standard
input and writing query results to standard output. The
Each query is presented on a single line of standard input and consists of two different integers
separated by a single space: the two regions
NOTE: The test data will be such that the correct answer to any query given on standard input
will always be less than
IMPORTANT NOTE: In order to interact properly with the grader, your program needs to flush standard output after every query response.
Grading
For a number of tests, worth a total of 30 points,
For a number of tests, worth a total of 55 points, no region will have more than
The tests where both of the above conditions hold are worth 15 points.
The tests where at least one of the two conditions holds are worth 70 points.
Sample Input
6 3 4
1
1 2
1 3
2 3
2 3
5 1
1 2
1 3
2 3
3 1
Sample Output
1
3
2
1
Comments