#P6838. [IOI 2020] 网络站点(无法评测)
[IOI 2020] 网络站点(无法评测)
Description
Singapore’s Internet backbone consists of network sites, which are assigned indices from to . The Internet also has bidirectional links, numbered from to . Each link connects two different sites. Two sites connected by a link are called neighbors of each other.
A sequence of distinct sites is called a path from site to site if and only if , , and every two consecutive sites in the sequence are neighbors. It is guaranteed that for any site and any other site , there exists exactly one path.
Any site can generate a packet and send it to any other site , where site is called the packet’s destination site. The packet must be routed along the unique path from site to site according to the following rules. Suppose the packet has currently arrived at site , where is the destination and . Then site will:
- Execute the routing function to find the neighbor of that lies on the unique path from to . Then
- Forward the packet to that neighbor.
However, sites have limited storage memory and may not be able to store the full list of backbone links needed by the routing function.
Your task is to implement the routing mechanism of the backbone, which consists of two functions.
- The first function takes as input , the list of backbone links, and an integer . This function must assign each site a unique label, with values between and (inclusive).
- The second function is the routing function. After the labels are assigned, it is deployed on all sites. Its input parameters are:
- , the label of the site where the packet is currently located,
- , the label of the destination site ,
- , the list of labels of all neighboring sites of .
This function should return the label of a neighbor of , indicating the next site to which the packet should be forwarded.
In each subtask, your score depends on the maximum label assigned among all sites (in general, the smaller the maximum label, the better).
Implementation Details
You need to implement the following functions:
int[] label(int n, int k, int[] u, int[] v)
- : the number of sites in the backbone.
- : the maximum available label value.
- and : arrays of size describing the links. For each , link connects the sites with indices and .
- This function should return an array of size . For each , is the label assigned to the site with index . All elements of must be pairwise distinct and between and (inclusive).
int find_next_station(int s, int t, int[] c)
- : the label of the site where the packet is currently located.
- : the label of the destination site.
- : an array containing the labels of all neighbors of . The array is sorted in increasing order.
- This function should return the label of a neighbor of , indicating the next site to which the packet should be forwarded.
Each test case contains one or more independent scenarios (i.e., different backbone descriptions). For a test case containing scenarios, the grader will run the above functions exactly twice, following the steps below.
During the first run:
- The
labelfunction is called times. - The returned labels are saved by the grading system.
find_next_stationis not called.
During the second run:
find_next_stationis called multiple times. For each call, the grader chooses an arbitrary scenario, and the labeling returned by thelabelfunction for that scenario is used for thisfind_next_stationcall.labelis not called.- In particular, any information stored in static or global variables during the first run of the grader cannot be used in the
find_next_stationfunction.
Input Format
Output Format
Hint
Sample Explanation
Example 1
Consider the following call:
label(5, 10, [0, 1, 1, 2], [1, 2, 3, 4])
There are sites and links. The pairs of site indices for the links are , , , and . The labels range from to .
To return the following labeling scheme:
| Index | Label |
|---|---|
the function label should return . The numbers in the figure below show the site indices (left) and the assigned labels (right).

Assume the labels are assigned as shown above, and consider the following call:
find_next_station(9, 6, [2, 7])
This means the packet is currently at the site with label , and its destination site has label . Along the path from the current site to the destination site, the site labels are . Therefore, the function should return , indicating that the packet should be forwarded to the site with label (whose index is ).
Consider another possible call:
find_next_station(2, 3, [3, 6, 9])
This function should return , because the destination site (label ) is a neighbor of the current site (label ), so the destination site directly receives the packet.
Constraints
For each call to label:
- (for all )
For each call to find_next_station, its input parameters come from labels produced by some previously chosen call to label. With respect to the produced labels:
- and are the labels of two different sites.
- is the sequence of labels of all neighbors of the site with label , sorted in increasing order.
For each test case, across all scenarios combined, the total length of all arrays passed to the function find_next_station does not exceed .
Subtasks
- (5 points) , no site will have more than neighbors.
- (8 points) , link connects sites and .
- (16 points) , at most one site has more than neighbors.
- (10 points) ,
- (61 points)
In subtask 5, you can receive partial credit. Let be the maximum label returned by label across all scenarios. For this subtask, your score is computed according to the table below:
| Maximum label | Score |
|---|---|
Sample Grader
The sample grader reads the input data in the following format:
Line :
Then follow blocks, each describing one scenario, in the following format:
Line :
Lines :
Line : , the number of calls to find_next_station
Lines : , the indices of the sites involved in the -th call to find_next_station. At this time, the packet is at site , the destination site is , and it should be forwarded to site .
The sample grader prints your output in the following format:
Line :
Then follow blocks corresponding to the scenarios in the input. Each block has the following format:
Lines : a site index, whose corresponding label is the result returned by the -th call to find_next_station.
Note: each time the sample grader is executed, it calls both label and find_next_station.
Translated by ChatGPT 5
京公网安备 11011102002149号