Migrations

시간 제한3초메모리 제한2048 MB

요약
루트 트리가 한 노드씩 공개될 때, 최대 50개의 정수를 전송해 관찰자가 가장 먼 두 노드를 고르게 하는 전략을 설계한다.
난이도

어려움10점 중 8점

유형
트리, 그리디, 구현, 수학
정답자
아직 제출이 없습니다

문제

The Natural History Museum is investigating the migration patterns of dinosaurs in Bolivia. Paleontologists have discovered dinosaur footprints at NN different sites, numbered from 00 to N−1N - 1 in order of decreasing age: site 00 contains the oldest footprints, while site N−1N - 1 holds the youngest.

The dinosaurs migrated to each site (except site 00) from a specific, older site. For every site ii such that 1≤i≤N−11 \leq i \leq N - 1, there exists exactly one older site P\[i]P\[i] (with P\[i]<iP\[i] < i) such that some dinosaurs migrated directly from site P\[i]P\[i] to site ii. 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 ii and P\[i]P\[i]. Note that for any two distinct sites xx and yy, it is possible to travel from xx to yy by traversing a sequence of connections. The distance between sites xx and yy is defined as the minimum number of connections required to travel from xx to yy.

For example, the following image displays a case with N=5N = 5 sites, where P\[1]=0P\[1] = 0, P\[2]=1P\[2] = 1, P\[3]=2P\[3] = 2, and P\[4]=2P\[4] = 2. One can travel from site 33 to site 44 through 22 connections, so the distance between them is 22.

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)(0, 3) and (0,4)(0, 4) have a distance of 33, which is the maximum. In such cases, any of the pairs attaining the maximum distance is considered valid.

Initially, the values of P\[i]P\[i] are not known. The Museum sends a research team to visit the sites 1,2,…,N−11, 2, \ldots, N-1, in order. Upon reaching each site ii (1≤i≤N−11 \leq i \leq N-1), the team performs both of the following actions:

  • Determines the value of P\[i]P\[i], that is, the source of migration to site ii.
  • Decides whether to send one message to the Museum or not to send any message from this site, based on the previously gathered information.

Messages are transmitted via an expensive satellite communication system, so each message must be an integer between 11 and 20,00020\\,000, inclusive. Additionally, the team is allowed to send at most 5050 messages in total.

Your task is to implement a strategy, through which:

  • The research team selects the sites from which messages are sent, along with the value of each message.
  • The Museum can determine a pair of sites with the maximum distance, based solely on the messages received from each site, knowing from which sites these messages were sent.

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.

제한

  • N=10,000N = 10\\,000
  • 0≤P\[i]<i0 \leq P\[i] < i for each ii such that 1≤i≤N−11 \leq i \leq N-1.

예제

이 문제는 공개된 예제가 없습니다.