| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 2048 MB | 10 | 2 | 2 | 100.000% |
The Natural History Museum is investigating the migration patterns of dinosaurs in Bolivia. Paleontologists have discovered dinosaur footprints at $N$ different sites, numbered from 0ドル$ to $N - 1$ in order of decreasing age: site 0ドル$ contains the oldest footprints, while site $N - 1$ holds the youngest.
The dinosaurs migrated to each site (except site 0ドル$) from a specific, older site. For every site $i$ such that 1ドル \leq i \leq N - 1,ドル there exists exactly one older site $P[i]$ (with $P[i] < i$) such that some dinosaurs migrated directly from site $P[i]$ to site $i$. A single older site may have been the source of migrations to multiple younger sites.
The paleontologists model each migration as an undirected connection between sites $i$ and $P[i]$. Note that for any two distinct sites $x$ and $y,ドル it is possible to travel from $x$ to $y$ by traversing a sequence of connections. The distance between sites $x$ and $y$ is defined as the minimum number of connections required to travel from $x$ to $y$.
For example, the following image displays a case with $N = 5$ sites, where $P[1] = 0,ドル $P[2] = 1,ドル $P[3] = 2,ドル and $P[4] = 2$. One can travel from site 3ドル$ to site 4ドル$ through 2ドル$ connections, so the distance between them is 2ドル$.
The Museum aims to identify a pair of sites with the maximum possible distance.
Note that the pair is not necessarily unique: for instance, in the example above, both pairs $(0, 3)$ and $(0, 4)$ have a distance of 3ドル,ドル which is the maximum. In such cases, any of the pairs attaining the maximum distance is considered valid.
Initially, the values of $P[i]$ are not known. The Museum sends a research team to visit the sites 1,ドル 2, \ldots, N-1,ドル in order. Upon reaching each site $i$ (1ドル \leq i \leq N-1$), the team performs both of the following actions:
Messages are transmitted via an expensive satellite communication system, so each message must be an integer between 1ドル$ and 20ドル,000円,ドル inclusive. Additionally, the team is allowed to send at most 50ドル$ messages in total.
Your task is to implement a strategy, through which:
Sending large numbers through the satellite is costly. Your score will depend on both the highest integer sent and the total number of messages transmitted.
You need to implement two procedures; one for the research team, and another one for the Museum.
The procedure you should implement for the research team is:
int send_message(int N, int i, int Pi)
This procedure should return $S[i]$ specifying the action taken by the research team at site $i$:
The procedure you should implement for the Museum is:
std::pair<int,int> longest_path(std::vector<int> S)
send_message(N, i, Pi).This procedure should return a pair of sites $(U, V)$ with the maximum distance.
In the actual grading, a program that calls the above procedures is run exactly two times.
send_message is called exactly $N - 1$ times.send_message may depend on the actions taken by the research team during the previous calls.longest_path is called exactly once. The only information available to longest_path from the first run is the array $S$.| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 30 | Site 0ドル$ and some other site have a maximum distance among all pairs of sites. |
| 2 | 70 | No additional constraints. |
Let $Z$ be the maximum integer appearing in the array $S,ドル and let $M$ be the number of messages sent by the research team.
In any of the test cases, if at least one of the following conditions hold, then the score of your solution for that test case will be 0ドル$ (reported as Output isn't correct in CMS):
longest_path is incorrect.Otherwise, your score for subtask 1 is calculated as follows:
| Condition | Score |
|---|---|
| 9ドル,998円 \leq Z \leq 20,000円$ | 10ドル$ |
| 102ドル \leq Z \leq 9 997$ | 16ドル$ |
| 5ドル \leq Z \leq 101$ | 23ドル$ |
| $Z \leq 4$ | 30ドル$ |
Your score for subtask 2 is calculated as follows:
| Condition | Score |
|---|---|
| 5ドル \leq Z \leq 20,000円$ and $M \leq 50$ | 35ドル - 25 \log_{4000}\left(\frac{Z}{5}\right)$ |
| $Z \leq 4$ and 32ドル \leq M \leq 50$ | 40ドル$ |
| $Z \leq 4$ and 9ドル \leq M \leq 31$ | 70ドル - 30 \log_{4}\left(\frac{M}{8}\right)$ |
| $Z \leq 4$ and $M \leq 8$ | 70ドル$ |
Let $N = 10,000円$. Consider the situation in which $P[1] = 0,ドル $P[2] = 1,ドル $P[3] = 2,ドル $P[4] = 2,ドル and $P[i] = 1$ for $i > 4$.
Assume that the research team's strategy is to send the message 10ドル \cdot V + U$ whenever the pair of sites $(U, V)$ with the maximum distance changes as a result of a send_message call.
Initially, the pair with the maximum distance is $(U, V) = (0, 0)$. Consider the following sequence of calls during the first run of the program:
| Procedure call | $(U, V)$ | Return value ($S[i]$) |
|---|---|---|
send_message(10000, 1, 0) |
$(0,1)$ | 10ドル$ |
send_message(10000, 2, 1) |
$(0,2)$ | 20ドル$ |
send_message(10000, 3, 2) |
$(0,3)$ | 30ドル$ |
send_message(10000, 4, 2) |
$(0,3)$ | 0ドル$ |
Note that in all the remaining calls the value of $P[i]$ is 1ドル$. This means that the pair with the maximum distance does not change, and the team does not send any more messages.
Then, in the second run of the program, the following call is made:
longest_path([0, 10, 20, 30, 0, ...])
The Museum reads the last message sent by the research team, which is $S[3] = 30,ドル and deduces that $(0, 3)$ is the pair of sites with the maximum distance. Therefore, the call returns $(0, 3)$.
Note that this approach does not always make it possible for the Museum to determine the pair with the maximum distance correctly.
The sample grader calls both send_message and longest_path in the same run, which is different from the actual grader.
Input format:
N
P[1] P[2] ... P[N-1]
Output format:
S[1] S[2] ... S[N-1]
U V
Note that you can use the sample grader with any value of $N$.
C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)