Stations
문제
Singapore's Internet Backbone (SIB) consists of stations, which are assigned indices from to . There are also bidirectional links, numbered from to . Each link connects two distinct stations. Two stations connected with a single link are called neighbours.
A path from station to station is a sequence of distinct stations , such that , , and every two consecutive stations in the path are neighbours. There is exactly one path from any station to any other station .
Any station can create a packet (a piece of data) and send it to any other station , which is called the packet's target. This packet must be routed along the unique path from to as follows. Consider a station that currently holds a packet, whose target station is (). In this situation station : 1. executes a routing procedure that determines the neighbour of which is on the unique path from to , 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 , the list of the links in the 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 a 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).