루트 0을 기준으로 한 트리에서 두 도시의 조상 관계를 코드만으로 판별할 수 있도록 각 도시에 작은 정수 코드를 부여하는 문제이다.
어려움8트리DFS수학구현아직 제출이 없습니다시간 제한2초메모리 제한512 MBThere are many cities in the Kingdom of JOI. The road network satisfies the following conditions:
Every day, in the Kingdom of JOI, many people depart from the city 0 to other cities. Because many people have two destinations, they sometimes ask the following queries: for two different cities X, Y, which one of (0), (1), (2) is satisfied?
Note that, in the above situation, exactly one of (0), (1), (2) is satisfied. When X = 0, we consider (1) is satisfied regardless of the value of Y. Similarly, when Y = 0, we consider (0) is satisfied regardless of the value of X.
It is known that, just like the road network in the Kingdom of JOI, the above Conditions 1–3 are satisfied in other countries as well. In the Kingdom of JOI, people plan to develop the following two machines so that they can be used also in other countries.
If large integers are assigned as codes, it is difficult to treat them. We want to develop machines so that smaller values are assigned as codes.
Note that, when Machine 2 is used, neither the number of cities N nor information of the road network is directly given to the machine.
In order to develop two machines as above, write the following two programs:
The sample grader reads the following data from the standard input.
When the program terminates successfully, the sample grader writes the following information to the standard output. (The quotation mark is not written actually.)
Accepted : max_code=123456.”Wrong Answer [1].”If your program is considered as several types of Wrong Answer, the sample grader reports only one of them.