Singapore's Internet Backbone (SIB) consists of n stations, which are assigned indices from 0 to n−1. There are also n−1 bidirectional links, numbered from 0 to n−2. Each link connects two distinct stations. Two stations connected with a single link are called neighbours.
A path from station x to station y is a sequence of distinct stations a_0,a_1,⋯,a_p, such that a_0=x, a_p=y, and every two consecutive stations in the path are neighbours. There is exactly one path from any station x to any other station y.
Any station x can create a packet (a piece of data) and send it to any other station y, which is called the packet's target. This packet must be routed along the unique path from x to y as follows. Consider a station z that currently holds a packet, whose target station is y (z=y). In this situation station z: 1. executes a routing procedure that determines the neighbour of z which is on the unique path from z to y, and 2. forwards the packet to this neighbour.
However, stations have limited memory and do not store the entire list of the links in SIB to use it in the routing procedure.
Your task is to implement a routing scheme for SIB, which consists of two procedures.
The first procedure is given n, the list of the links in the SIB and an integer k≥n−1 as the inputs. It assigns each station a unique integer label between 0 and k, 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:
It should return the label of the neighbour of s 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).
For each call to label:
For each call to find_next_station, the input comes from an arbitrarily chosen previous call to label. Consider the labels it produced. Then:
For each test case, the total length of all arrays c passed to the procedure find_next_station does not exceed 100;000 for all scenarios combined.