#P16453. [APIO 2026] Navigation
[APIO 2026] Navigation
题目背景
When submitting this problem on Luogu, please do not include the header file navigation.h.
题目描述
Taiwan Province has a high density of high mountains, featuring over peaks above meters. A-Ming plans to construct robotic zipline delivery networks in the Central Mountain Range of Taiwan Province, to transport packages between the remote villages.
In A-Ming's plan, each network consists of nodes, numbered from to . Among these nodes, exactly of them are power stations and other nodes are all village nodes. The nodes are connected by bidirectional cables, numbered from to . For each (), cable connects nodes and . Each cable connects two different nodes, and each pair of nodes is connected by at most one cable. It is guaranteed that it is possible to move between any pair of nodes using the cables.
The distance of nodes and is denoted by and defined as follows.
- If then .
- Otherwise, is the minimum number of cables needed to move from to .
We say that the branching factor of the network is at least if each node in the network is either connected to exactly or at least cables. A-Ming knows a positive integer such that the branching factor of the network is at least .
A-Ming prepared different types of cables, numbered . Each cable in the network will be built with one of those types.
The robots will ride along the zipline cables to carry out delivery tasks. A-Ming would like to install a navigation program that helps the robots to return to the power stations and charge themselves. However, the robots have extremely low memory. Hence, in designing the navigation program, the robots navigate only based on the number of power stations , the guaranteed branching factor , and the types of cable attached to the robot's current location.
When a robot wants to navigate at a village node connected to two or more cables, the robot first scans the cables connected to in an arbitrary order. The program is then provided with a list containing the types of the cables in the order. For each of the cables, the program needs to count the number of power stations such that following the cable decreases the distance between the robot and the station.
Specifically, let () be the nodes directly connected to by a cable and () be the type of the cable connecting node and . The program is then provided with , , and the list . For each (), the program has to determine the number of power stations such that .
Your task is to devise a strategy to assign the cable types and design the navigation program. The score of your solution depends on the number of different type of cables used (see Subtasks and Scoring section for details).
Implementation details
You need to implement two procedures, one for assigning the cable types and another for the robots' program.
The procedure you should implement to assign the cable types is:
std::vector<int> construct_network(int N, int K, int B,
std::vector<int> U, std::vector<int> V,
std::vector<int> P)
- : the number of nodes.
- : the number of power stations.
- : the guaranteed minimum branching factor of the network.
- : arrays of lengths describing cable connections.
- : an array of length describing the power station nodes.
- This procedure is called at most times for each test case.
This procedure should return an array of length :
- A cable with type is used to connect nodes and .
- Each element must satisfy .
The procedure you should implement for the robots' program is:
std::vector<int> navigate(int K, int B, std::vector<int> C)
- : the number of power stations.
- : the guaranteed minimum branching factor of the network.
- : the list of the types of all cables connected to some village node connected to at least 2 cables, in an arbitrary order.
- It is guaranteed that the length of is at least .
- This procedure is called at most times for each test case.
- The procedure
navigatemay not rely on the original network structure; in particular, the grading system may reorder all calls tonavigateacross the different constructed networks within the same test case.
This procedure should return an array :
- The length of array must be the same as array .
- must be the number of power stations where following the cable corresponding to decreases the distance between the robot and the station.
Note that in the grading system, the construct_network and navigate procedures are called in two separate processes.
输入格式
The sample grader calls both construct_network and navigate in the same process. In addition, when the sample grader calls navigate, the cable types are listed in the order in which their corresponding cables appear in the input. Both behaviors are different from the actual grader.
Input format:
T
(scenario 0)
(scenario 1)
...
(scenario T-1)
Each scenario is in the following format:
N
B
U[0] V[0]
U[1] V[1]
...
U[N-2] V[N-2]
K
P[0] P[1] ... P[K-1]
Q
X[0] X[1] ... X[Q-1]
In each scenario, the sample grader will call navigate times, the -th call with the information of node . Note that the sample grader supports setting to integers other than .
输出格式
If any of the returned arrays of construct_network or navigate is invalid, the sample grader aborts and prints the reason. Otherwise, the sample grader outputs each array returned from the navigate call in a line.
After all scenarios have been processed, the sample grader prints a line to the standard error:
S = S'
where is the smallest integer greater than all numbers in every array returned from each construct_network call in the test case.
提示
Example
Consider the scenario in which , , and .
The network plan is specified by , . The power stations are . Consider the following call to the first process:
construct_network(9, 6, 2, [0, 0, 0, 2, 2, 2, 2, 7],
[1, 2, 3, 4, 5, 6, 7, 8],
[1, 3, 4, 5, 6, 7])
Suppose A-Ming builds the network by returning:
[0, 10, 1, 2, 3, 4, 5, 5]
The constructed network is illustrated as follows.
:::align{center}
:::
Then, in the second process, suppose the robot needs to navigate at node . The node is connected to node , and . If the robot reads the cable type in this order, the following call will be made:
navigate(6, 2, [0, 10, 1])
Based on the network structure:
- The first power station, node , has the shortest distance to itself. In particular, .
- The second power station, node , has the shortest distance to itself. In particular, .
- Other power stations, node , , , and , have shorter distances to node . In particular, when , or .
The number of power stations with distance decreased after following cables , , and are , and , respectively. Hence, the procedure should return:
[1, 4, 1]
Note that navigate can also be called for different permutations of . For example, navigate(6, 2, [1, 0, 10]) is also a possible call for node . The procedure should return [1, 1, 4] accordingly.
Suppose the robot needs to navigate at node . The following call is made:
navigate(6, 2, [10, 2, 3, 4, 5])
The procedure should return:
[2, 1, 1, 1, 1]
In this network, the procedure navigate would never be called for other nodes, since:
- node , , , , and are all power stations, and
- node is connected to only one cable.
In this test case, the used cable types are , , , , , , and . Thus, will be used to determine the score.
The attachment package for this task contains two other sample inputs and outputs for the sample grader in addition to this example.
Constraints
- .
- .
- The sum of over all calls to
construct_networkdoes not exceed in each test case. - for each .
- It is possible to move from any node to any other node using the cables.
- .
- Each array is a permutation of the list of the types of all cables connected to some village node that is connected to at least cables.
- The sum of the lengths of array over all calls to
navigatedoes not exceed in each test case.
Subtasks and Scoring
| Subtask | Score | Additional Constraints |
|---|---|---|
| . | ||
| for each such that . | ||
| . | ||
| . | ||
| . |
In any of the test cases, if at least one of the following conditions holds, then the score of your solution for that test case will be (reported as Output isn't correct in CMS):
- The return value of any call to
construct_networkis invalid. - The return value of any call to
navigateis incorrect.
Otherwise, let be the smallest integer greater than all numbers in every array returned from each construct_network call. In other words, is the smallest integer such that all constructed networks only use cables of type .
Your score for each subtask depends on , as follows:
| Condition | Subtask 1 | Subtask 2 | Subtask 3 and 4 | Subtask 5 |
|---|---|---|---|---|
In particular, in Subtask , and , you will receive full point if , and in Subtask and , you will receive full point if .