Singapore's Internet Backbone (SIB) consists of
A path from station
Any station
- executes a routing procedure that determines the neighbour of
which is on the unique path from to , and - forwards the packet to this neighbour.
However, stations have limited memory and do not share the entire list of the links in SIB to use it in the routing procedure.
Your task is to implement a routing scheme in SIB, which consists of two procedures.
- The first procedure is given
, the list of the links in SIB and an integer as the inputs. It assigns each station a unique integer label between and , inclusive. The second procedure is the routing procedure, which is deployed to all stations after labels are assigned. It is given only the following inputs:
, the label of the station that currently holds the packet, , the label of the packet's target station , , the list of the labels of all neighbours of .
It should return the label of the neighbour of
that the packet should be forwarded to.
In one subtask, the score of your solution depends on the value of the maximum label assigned to any station (in general, smaller is better).
Implementation Details
You should implement the following procedures:
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v)
: number of stations in SIB. : maximum label that can be used. and : array of sizes describing the links. For each , link connects stations with indices and .- This procedure should return a single array
of size . For each , is the label assigned to the station with index . All elements of array must be unique and between and , inclusive.
int find_next_station(int s, int t, std::vector<int> c)
: label of the station holding the packet. : label of the packet's target station. : an array giving the list of the labels of all neighbours of . The array is sorted in ascending order.- This procedure should return the label of a neighbour of
that the packet should be forwarded to.
Each test case involves one or more independent scenarios (i.e., different SIB descriptions).
For a test case involving
During the first run of the program:
label
procedure is called times,- the returned labels are stored by the grading system, and
find_next_station
is not called.
During the second run of the program:
find_next_station
may be called multiple times. In each call, an arbitrary scenario is chosen, and the labels returned by the call tolabel
procedure in that scenario are used as the inputs tofind_next_station
.label
is not called.
In particular, any information saved to static or global variables in the first run of the program is not available within the find_next_station
procedure.
Example
Consider the following call:
label(5, 10, [0, 1, 1, 2], [1, 2, 3, 4])
There are a total of
In order to report the following labeling:
Index | Label |
---|---|
The label
procedure should return
Assume the labels have been assigned as described above and consider the following call:
find_next_station(9, 6, [2, 7])
This means that the station holding the packet has label
Consider another possible call:
find_next_station(2, 3, [3, 6, 9])
The procedure should return
Constraints
For each call to label
:
(for all )
For each call to find_next_station
, the input comes from an arbitrarily chosen previous call to label
. Consider the labels it produced. Then:
and are labels of two different stations. is the sequence of all labels of neighbours of the station with label , in ascending order.
For each test case, the total length of all arrays find_next_station
does not exceed
Subtasks
- (
points) , no station has more than neighbours. - (
points) , link connects station and . - (
points) , at most one station has more than neighbours. - (
points) , . - (
points) .
In subtask label
across all scenarios.
Your score for this subtask is calculated according to the following table:
Maximum label | Score |
---|---|
Sample Grader
The sample grader reads the input in the following format:
- line
:
- line
: - line
: - line
: : the number of calls tofind_next_station
. - line
: : indices of stations involved in the -th call tofind_next_station
. The station holds the packet, the station is the packet's target, and the station is the station that the packet should be forwarded to.
The sample grader prints the result in the following format:
- line
:
- line
: index of the station, whose label was returned by the -th call tofind_next_station
in this scenario.
Note that each run of the sample grader calls both label
and find_next_station
.
Attachment Package
The sample grader along with sample test cases are available here.
Comments