시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 33 | 8 | 7 | 25.926% |
There 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:
You need to submit two files .
The first file is Encoder.cpp
. This file implements Machine 1. It should implement the following function. The program should include Encoder.h
.
void Encode(int N, int A[], int B[])
N
is the number of cities N.A[]
, B[]
are integer sequences of length N − 1 describing the road network. The elements A[i]
, B[i]
(0 ≤ i ≤ N − 2) mean there is a road connecting the city A[i]
and the city B[i]
directly.Your program should call the following function.
void Code(int city, long long code)
city
is the city to which a code is assigned. The parameter city
should be an integer between 0 and N − 1, inclusive. If the call to this function has parameters outside this range, your program is considered as Wrong Answer [1]. It should not be called twice with the same parameters. If it is called twice with the same parameters, your program is considered as Wrong Answer [2].code
is the code assigned to the city whose number is city
. The parameter code
should be an integer between 0 and 260 − 1, inclusive. If the call to this function has parameters outside this range, your program is considered as Wrong Answer [3].Your program should call the function Code
exactly N times. If the number of calls to Code
is not N when the function Encode
is terminated, your program is considered as Wrong Answer [4].
If the call to the function Encode is considered Wrong Answer, your program is terminated immediately.
The second file is either Device.cpp
. This file implements Machine 2. It should implement the following function. The program should include Device.h
.
void InitDevice()
InitDevice
is called once before calls to the following function Answer
.int Answer(long long S, long long T)
Answer
is called once.
S
, T
are the codes assigned to two different cities X, Y by the function Encode
.Answer
should satisfy the following conditions:
0
if we necessarily pass the city Y when we travel from the city 0 to the city X.1
if we necessarily pass the city X when we travel from the city 0 to the city Y.Hence the return value of the function Answer
should be an integer between 0 and 2, inclusive. If the return value is outside this range, your program is considered as Wrong Answer [5]. If the return value is inside this range but it does not satisfy the above conditions, your program is considered as Wrong Answer [6].
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.
There are no additional constraints. In this subtask, the score is calculated as follows:
Here is a sample input for sample grader and corresponding function calls.
Sample Input | Sample Calls | |
---|---|---|
Machine 1 | Machine 2 | |
6 5 4 1 0 3 4 5 3 2 3 4 2 4 2 1 0 0 5 1 2 5 3 0 4 1 1 |
Encode(6, {4, 0, 4, 3, 3}, {1, 3, 5, 2, 4}) |
|
Code(0,0) |
||
Code(2,4) |
||
Code(4,16) |
||
Code(1,1) |
||
Code(3,9) |
||
Code(5,25) |
||
InitDevice() |
||
Answer(4,16) |
||
Answer(1,0) |
||
Answer(25,1) |
||
Answer(25,9) |
||
Answer(16,1) |
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)