Taiwan has a big railway line connecting the western and eastern shores of the island. The line consists of
There are three types of blocks. A type C block has a train station that you must enter from the northern track and exit to the southern track, a type D block has a train station that you must enter from the southern track and exit to the northern track, and a type empty block has no train station. For example, in the following figure block
The rail system has
Since there are multiple possible routes, the distance from one station to another is defined as the minimum number of connectors the route passes through. For example the shortest route from station
A computer system manages the rail system. Unfortunately after a power outage the computer no longer knows where the stations are and what types of blocks they are in. The only clue the computer has is the block number of station
Task
You need to implement a function findLocation
that determines for each station the block number and block type.
findLocation(n, first, location, stype)
n
: the number of stations.first
: the block number of station .location
: array of size ; you should place the block number of station intolocation[i]
.stype
: array of size ; you should place the block type of station intostype[i]
: for type C and for type D.
You can call a function getDistance
to help you find the locations and types of stations.
getDistance(i, j)
returns the distance from station to station .getDistance(i, i)
will return .getDistance(i, j)
will return if or is outside the range .
Subtasks
In all subtasks the number of blocks getDistance
is limited. The limit varies by subtask. Your program will receive 'wrong answer' if it exceeds this limit.
subtask | points | getDistance calls | note | |
---|---|---|---|---|
1 | 8 | unlimited | All stations except | |
2 | 22 | unlimited | All stations to the right of station | |
3 | 26 | no additional limits | ||
4 | 44 | no additional limits |
Implementation details
You have to submit exactly one file. This file implements findLocation
as described above using the following signature.
void findLocation(int n, int first, int location[], int stype[]);
Comments