luogu#P4899. [IOI 2018] werewolf 狼人
[IOI 2018] werewolf 狼人
Background
This problem is an interactive problem, but here you should submit a full program.
Problem Description
In Ibaraki Prefecture, Japan, there are cities and roads. The cities are sorted in increasing order of population and are numbered from to . Each road connects two different cities and can be traveled in both directions. Using these roads, you can travel from any city to any other city.
You have planned trips, numbered from to . Trip goes from city to city .
You are a werewolf. You have two forms: human form and wolf form. At the start of each trip, you are in human form. At the end of each trip, you must be in wolf form. During the trip, you must transform (from human form to wolf form) exactly once, and you can only transform inside a city (possibly at or ).
Life as a werewolf is not easy. When you are in human form, you must avoid cities with small populations, and when you are in wolf form, you must avoid cities with large populations. For each trip , there are two thresholds and that describe which cities must be avoided. More precisely, when you are in human form, you must avoid cities ; when you are in wolf form, you must avoid cities . This means that in trip , you must transform in one of the cities .
Your task is: for each trip, determine whether it is possible to travel from city to city while satisfying the restrictions above. Your route may have any length.
Input Format
The first line contains three positive integers , as described above.
The next lines each contain two non-negative integers. In these lines, the -th line contains , meaning that road number connects those two cities.
The next lines each contain four non-negative integers. In these lines, the -th line contains , meaning that trip number starts at city , ends at city , and has the two thresholds.
Output Format
Output lines, each containing an integer that is either or . The integer on line indicates whether, for trip number , it is possible to travel from city to city . Output if it is possible, otherwise output .
6 6 3
5 1
1 2
1 3
3 4
3 0
5 2
4 2 1 2
4 2 2 2
5 4 3 4
1
0
0
10 9 10
6 7
1 5
8 0
2 9
9 4
2 7
8 5
6 0
3 4
4 9 0 9
8 1 8 9
1 8 1 8
8 3 5 5
8 9 3 9
0 1 0 2
9 0 6 6
1 7 1 8
9 4 5 6
9 5 0 9
1
1
1
0
1
1
0
1
0
1
Hint
Constraints
- For each
- You can travel from any city to any other city using the roads.
- Each pair of cities is directly connected by at most one road. In other words, for all , and .
- For each
Subtasks
-
- (7 points) , , .
-
- (8 points) , , .
-
- (34 points) and each city is connected to at most two roads (all cities form a single line).
-
- (51 points) No additional constraints.
Translated by ChatGPT 5