#P16453. [APIO 2026] Navigation

    ID: 16436 Type: RemoteJudge 2000ms 2048MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>APIO交互题Special Judge2026通信题

[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 250250 peaks above 3,0003,000 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 NN nodes, numbered from 00 to N1N - 1. Among these nodes, exactly K=6K = 6 of them are power stations and other NKN - K nodes are all village nodes. The nodes are connected by N1N - 1 bidirectional cables, numbered from 00 to N2N - 2. For each ii (0iN20 \le i \le N - 2), cable ii connects nodes U[i]U[i] and V[i]V[i]. 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 aa and bb is denoted by d(a,b)d(a,b) and defined as follows.

  • If a=ba = b then d(a,b)=0d(a, b) = 0.
  • Otherwise, d(a,b)d(a, b) is the minimum number of cables needed to move from aa to bb.

We say that the branching factor of the network is at least δ\delta if each node in the network is either connected to exactly 11 or at least δ\delta cables. A-Ming knows a positive integer BB such that the branching factor of the network is at least BB.

A-Ming prepared 100100 different types of cables, numbered 0,1,,990, 1, \ldots, 99. 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 K=6K = 6, the guaranteed branching factor BB, and the types of cable attached to the robot's current location.

When a robot wants to navigate at a village node uu connected to two or more cables, the robot first scans the cables connected to uu 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 v1,,vkv_1, \ldots, v_k (k2k \ge 2) be the nodes directly connected to uu by a cable and cic_i (1ik1 \le i \le k) be the type of the cable connecting node uu and viv_i. The program is then provided with KK, BB, and the list c1,c2,,ckc_1, c_2, \ldots, c_k. For each ii (1ik1 \le i \le k), the program has to determine the number of power stations pp such that d(vi,p)<d(u,p)d(v_i, p) < d(u, p).

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)
  • NN: the number of nodes.
  • KK: the number of power stations.
  • BB: the guaranteed minimum branching factor of the network.
  • U,VU, V: arrays of lengths N1N - 1 describing cable connections.
  • PP: an array of length K=6K = 6 describing the power station nodes.
  • This procedure is called at most 10 00010\ 000 times for each test case.

This procedure should return an array TT of length N1N - 1:

  • A cable with type T[i]T[i] is used to connect nodes U[i]U[i] and V[i]V[i].
  • Each element T[i]T[i] must satisfy 0T[i]<1000 \le T[i] < 100.

The procedure you should implement for the robots' program is:

std::vector<int> navigate(int K, int B, std::vector<int> C)
  • KK: the number of power stations.
  • BB: the guaranteed minimum branching factor of the network.
  • CC: 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 CC is at least BB.
  • This procedure is called at most 100 000100\ 000 times for each test case.
  • The procedure navigate may not rely on the original network structure; in particular, the grading system may reorder all calls to navigate across the different constructed networks within the same test case.

This procedure should return an array DD:

  • The length of array DD must be the same as array CC.
  • D[i]D[i] must be the number of power stations where following the cable corresponding to C[i]C[i] 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 QQ times, the ii-th call with the information of node X[i1]X[i - 1]. Note that the sample grader supports setting KK to integers other than 66.

输出格式

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 DD 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 SS' is the smallest integer greater than all numbers in every array TT returned from each construct_network call in the test case.



提示

Example

Consider the scenario in which N=9N = 9, K=6K = 6, and B=2B = 2.

The network plan is specified by U=[0,0,0,2,2,2,2,7]U = [0,0,0,2,2,2,2,7], V=[1,2,3,4,5,6,7,8]V = [1,2,3,4,5,6,7,8]. The power stations are P=[1,3,4,5,6,7]P = [1,3,4,5,6,7]. 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 00. The node 00 is connected to node 11, 22 and 33. 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 11, has the shortest distance to itself. In particular, 0=d(1,1)<1=d(0,1)<2=d(2,1)=d(3,1)0 = d(1,1) < 1 = d(0,1) < 2 = d(2,1) = d(3,1).
  • The second power station, node 33, has the shortest distance to itself. In particular, 0=d(3,3)<1=d(0,3)<2=d(1,3)=d(2,3)0 = d(3,3) < 1 = d(0,3) < 2 = d(1,3) = d(2,3).
  • Other power stations, node 44, 55, 66, and 77, have shorter distances to node 22. In particular, 1=d(2,u)<2=d(0,u)<3=d(1,u)=d(3,u)1 = d(2,u) < 2 = d(0,u) < 3 = d(1,u) = d(3,u) when u=4,5,6u = 4,5,6, or 77.

The number of power stations with distance decreased after following cables (0,1)(0,1), (0,2)(0,2), and (0,3)(0,3) are 11, 44 and 11, respectively. Hence, the procedure should return:

[1, 4, 1]

Note that navigate can also be called for different permutations of CC. For example, navigate(6, 2, [1, 0, 10]) is also a possible call for node 00. The procedure should return [1, 1, 4] accordingly.

Suppose the robot needs to navigate at node 22. 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 11, 33, 44, 55, 66 and 77 are all power stations, and
  • node 88 is connected to only one cable.

In this test case, the used cable types are 00, 11, 22, 33, 44, 55, and 1010. Thus, S=11S = 11 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

  • K=6K = 6.
  • K<N100 000K < N \le 100\ 000.
  • The sum of NN over all calls to construct_network does not exceed 100 000100\ 000 in each test case.
  • 0U[i]<V[i]<N0 \le U[i] < V[i] < N for each 0iN20 \le i \le N - 2.
  • It is possible to move from any node to any other node using the cables.
  • 0P[0]<P[1]<<P[K1]<N0 \le P[0] < P[1] < \cdots < P[K-1] < N.
  • Each array CC is a permutation of the list of the types of all cables connected to some village node that is connected to at least 22 cables.
  • The sum of the lengths of array CC over all calls to navigate does not exceed 200 000200\ 000 in each test case.

Subtasks and Scoring

Subtask Score Additional Constraints
11 66 B=2,N=7B = 2, N = 7.
22 1414 B=2,U[i]=i,V[i]=i+1B = 2, U[i] = i, V[i] = i + 1 for each ii such that 0i<N10 \le i < N - 1.
33 2020 B=5B = 5.
44 B=4B = 4.
55 4040 B=2B = 2.

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 00 (reported as Output isn't correct in CMS):

  • The return value of any call to construct_network is invalid.
  • The return value of any call to navigate is incorrect.

Otherwise, let SS be the smallest integer greater than all numbers in every array TT returned from each construct_network call. In other words, SS is the smallest integer such that all constructed networks only use cables of type 0,1,,S10, 1, \ldots, S - 1.

Your score for each subtask depends on SS, as follows:

Condition Subtask 1 Subtask 2 Subtask 3 and 4 Subtask 5
100<S100 < S 00
16S10016 \le S \le 100 22 22 12log2S12 - \log_2 S 242log2S24 - 2\log_2 S
10S1510 \le S \le 15 44 160.5S16 - 0.5S 32S32 - S
7S97 \le S \le 9 66 21S21 - S 422S42 - 2S
S=6S = 6 1010 1515 3030
S=5S = 5 6\bm6 14\bm{14} 17.517.5 40\bm{40}
S4S \le 4 20\bm{20}

In particular, in Subtask 11, 22 and 55, you will receive full point if S5S \le 5, and in Subtask 33 and 44, you will receive full point if S4S \le 4.