IOI '18 P3 - Werewolf
View as PDFThere are  cities and 
 roads in Ibaraki Prefecture, Japan. Cities are numbered from 
 through 
 in the increasing order of their population. Each road connects a pair of distinct cities, and can be traveled in both directions. You can travel from any city to any other city by using one or more of these roads.
You planned  trips, numbered from 
 through 
. The trip 
 
 is to travel from the city 
 to the city 
.
You are a werewolf. You have two forms: human form and wolf form. At the beginning of each trip you are in human form. At the end of each trip, you must be in wolf form. During the trip you have to transform (change from human form to wolf form) exactly once. You can transform only when you are in some city (possibly  or 
).
Living as a werewolf is not easy. You must avoid low-populated cities when you are in human form, and avoid highly-populated cities when you are in wolf form. For each trip  
, there are two thresholds 
 and 
 
 that indicate which cities must be avoided. More specifically, you must avoid the cities 
 when you are in human form, and must avoid the cities 
 when you are in wolf form. This means in the trip 
, you can only transform in one of the cities 
.
Your task is to determine, for each trip, whether it is possible to travel from the city  to the city 
 in a way that satisfies the aforementioned constraints. The route you take can have an arbitrary length.
Implementation details
You should implement the following function:
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y, std::vector<int> S, std::vector<int> E, std::vector<int> L, std::vector<int> R)
: the number of cities.
and
: arrays of length
. For each
, the city
X[j]is directly connected to the cityY[j]by a road.,
,
, and
: arrays of length
, representing the trips.
Note that the values of  and 
 are the lengths of the arrays, and can be obtained as indicated in the implementation notice.
The function check_validity is called exactly once for each test case. This function should return an array  of integers of length 
. The value of 
 
 must be 
 if the trip 
 is possible while satisfying the aforementioned conditions, or 
 otherwise.
Example
Let , 
, 
, 
, 
, 
, 
, 
, 
.
check_validity(6, {5, 1, 1, 3, 3, 5}, {1, 2, 3, 4, 0, 2}, {4, 4, 5}, {2, 2, 4}, {1, 2, 3}, {2, 2, 4})
For the trip , you can travel from the city 
 to the city 
 as follows:
- Start at city 
(You are in human form)
 - Move to the city 
(You are in human form)
 - Move to city 
(You are in human form)
 - Transform yourself into wolf form (You are in wolf form)
 - Move to the city 
(You are in wolf form)
 
For the trips  and 
, you cannot travel between the given cities.
Hence, your program should return [1, 0, 0].
Constraints
- For each 
 - You can travel from any city to any other city by using roads.
 - Each pair of cities are directly connected by at most one road. In other words, for all 
,
and
.
 - For each 
 
Subtasks
| Subtask | Points | Constraints | 
|---|---|---|
| No additional constraints | 
Sample Grader
The sample grader reads the input in the following format:
- line 
:
 - line 
:
 - line 
:
 
The sample grader prints the return value of check_validity in the following format:
- line 
:
 
Comments