Migrations
문제
The Natural History Museum is investigating the migration patterns of dinosaurs in Bolivia. Paleontologists have discovered dinosaur footprints at different sites, numbered from to in order of decreasing age: site contains the oldest footprints, while site holds the youngest.
The dinosaurs migrated to each site (except site ) from a specific, older site. For every site such that , there exists exactly one older site (with ) such that some dinosaurs migrated directly from site to site . 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 and . Note that for any two distinct sites and , it is possible to travel from to by traversing a sequence of connections. The distance between sites and is defined as the minimum number of connections required to travel from to .
For example, the following image displays a case with sites, where , , , and . One can travel from site to site through connections, so the distance between them is .
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 and have a distance of , which is the maximum. In such cases, any of the pairs attaining the maximum distance is considered valid.
Initially, the values of are not known. The Museum sends a research team to visit the sites , in order. Upon reaching each site (), the team performs both of the following actions:
- Determines the value of , that is, the source of migration to site .
- 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 and , inclusive. Additionally, the team is allowed to send at most 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.