#P6838. [IOI 2020] 网络站点(无法评测)

    ID: 5878 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2020IOI交互题Special Judge深度优先搜索,DFS

[IOI 2020] 网络站点(无法评测)

Description

Singapore’s Internet backbone consists of nn network sites, which are assigned indices from 00 to n1n-1. The Internet also has n1n-1 bidirectional links, numbered from 00 to n2n-2. Each link connects two different sites. Two sites connected by a link are called neighbors of each other.

A sequence of distinct sites a0,a1,,apa_0,a_1,\ldots,a_p is called a path from site xx to site yy if and only if a0=xa_0=x, ap=ya_p=y, and every two consecutive sites in the sequence are neighbors. It is guaranteed that for any site xx and any other site yy, there exists exactly one path.

Any site xx can generate a packet and send it to any other site yy, where site yy is called the packet’s destination site. The packet must be routed along the unique path from site xx to site yy according to the following rules. Suppose the packet has currently arrived at site zz, where yy is the destination and zyz \ne y. Then site zz will:

  1. Execute the routing function to find the neighbor of zz that lies on the unique path from zz to yy. Then
  2. 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 nn, the list of backbone links, and an integer kn1k \ge n-1. This function must assign each site a unique label, with values between 00 and kk (inclusive).
  • The second function is the routing function. After the labels are assigned, it is deployed on all sites. Its input parameters are:
    • ss, the label of the site where the packet is currently located,
    • tt, the label of the destination site (ts)(t \ne s),
    • cc, the list of labels of all neighboring sites of ss.

This function should return the label of a neighbor of ss, 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)
  • nn: the number of sites in the backbone.
  • kk: the maximum available label value.
  • uu and vv: arrays of size n1n-1 describing the links. For each i(0in2)i(0 \le i \le n-2), link ii connects the sites with indices u[i]u[i] and v[i]v[i].
  • This function should return an array LL of size nn. For each i(0in1)i(0 \le i \le n-1), L[i]L[i] is the label assigned to the site with index ii. All elements of LL must be pairwise distinct and between 00 and kk (inclusive).
int find_next_station(int s, int t, int[] c)
  • ss: the label of the site where the packet is currently located.
  • tt: the label of the destination site.
  • cc: an array containing the labels of all neighbors of ss. The array cc is sorted in increasing order.
  • This function should return the label of a neighbor of ss, 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 rr scenarios, the grader will run the above functions exactly twice, following the steps below.

During the first run:

  • The label function is called rr times.
  • The returned labels are saved by the grading system.
  • find_next_station is not called.

During the second run:

  • find_next_station is called multiple times. For each call, the grader chooses an arbitrary scenario, and the labeling returned by the label function for that scenario is used for this find_next_station call.
  • label is 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_station function.

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 55 sites and 44 links. The pairs of site indices for the links are (0,1)(0,1), (1,2)(1,2), (1,3)(1,3), and (2,4)(2,4). The labels range from 00 to k=10k=10.

To return the following labeling scheme:

Index Label
00 66
11 22
22 99
33
44 77

the function label should return [6,2,9,3,7][6,2,9,3,7]. 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 99, and its destination site has label 66. Along the path from the current site to the destination site, the site labels are [9,2,6][9,2,6]. Therefore, the function should return 22, indicating that the packet should be forwarded to the site with label 22 (whose index is 11).

Consider another possible call:

find_next_station(2, 3, [3, 6, 9])

This function should return 33, because the destination site (label 33) is a neighbor of the current site (label 22), so the destination site directly receives the packet.

Constraints

  • 1r101 \le r \le 10

For each call to label:

  • 2n10002 \le n \le 1000
  • kn1k \ge n-1
  • 0u[i],v[i]n10 \le u[i],v[i] \le n-1(for all 0in20 \le i \le n-2

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:

  • ss and tt are the labels of two different sites.
  • cc is the sequence of labels of all neighbors of the site with label ss, sorted in increasing order.

For each test case, across all scenarios combined, the total length of all arrays cc passed to the function find_next_station does not exceed 10510^5.

Subtasks

  1. (5 points) k=1000k=1000, no site will have more than 22 neighbors.
  2. (8 points) k=1000k=1000, link ii connects sites i+1i+1 and i2\lfloor\frac{i}{2}\rfloor.
  3. (16 points) k=106k=10^6, at most one site has more than 22 neighbors.
  4. (10 points) n8n \le 8, k=109k = 10^9
  5. (61 points) k=109k = 10^9

In subtask 5, you can receive partial credit. Let mm 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
m109m \ge 10^9 00
2000m<1092000 \le m < 10^9 50log5105(109m)50 \cdot \log_{5 \cdot10^5}(\frac{10^9}{m})
1000<m<50001000 < m < 5000 5050
m1000m \le 1000 6161

Sample Grader

The sample grader reads the input data in the following format:

Line 11: rr

Then follow rr blocks, each describing one scenario, in the following format:

Line 11: n kn\ k
Lines 2+i(0in2)2+i(0 \le i \le n-2): u[i] v[i]u[i]\ v[i]
Line 1+n1+n: qq, the number of calls to find_next_station
Lines 2+n+j(0jq1)2+n+j(0 \le j \le q-1): z[j] y[j] w[j]z[j]\ y[j]\ w[j], the indices of the sites involved in the jj-th call to find_next_station. At this time, the packet is at site z[j]z[j], the destination site is y[j]y[j], and it should be forwarded to site w[j]w[j].

The sample grader prints your output in the following format:

Line 11: mm

Then follow rr blocks corresponding to the scenarios in the input. Each block has the following format:

Lines 1+j(0jq1)1+j(0 \le j \le q-1): a site index, whose corresponding label is the result returned by the jj-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