#P4899. Werewolf Transformation Journey
Werewolf Transformation Journey
Werewolf Transformation Journey
In Ibaraki, Japan, there are \(N\) cities (numbered from \(0\) to \(N-1\) in increasing order of population) connected by \(M\) bidirectional roads, such that any city is reachable from any other.
You have planned \(Q\) trips. In the \(i\)th trip, you travel from city \(S_i\) to city \(E_i\). You are a werewolf with two forms: human and wolf. At the start of each trip, you are in human form, and by the end you must be in wolf form. During the journey, you must transform exactly once (from human to wolf) at some city (this city can be \(S_i\) or \(E_i\) as well).
However, your life is not easy. While human, you must avoid cities with low populations; while wolf, you must avoid cities with high populations. For each trip \(i\) there are two thresholds \(L_i\) and \(R_i\) (with \(0 \le L_i \le R_i \le N-1\)). This means that in the human phase you are not allowed to visit any city numbered less than \(L_i\), and in the wolf phase you are not allowed to visit any city numbered greater than \(R_i\). Consequently, the transformation must occur in a city whose number is between \(L_i\) and \(R_i\) (inclusive).
Your task is to determine for each trip whether it is possible to travel from city \(S_i\) to city \(E_i\) while satisfying the above restrictions. The route may be of arbitrary length.
inputFormat
The first line contains three integers \(N\), \(M\) and \(Q\) representing the number of cities, roads, and trips respectively.
The next \(M\) lines each contain two integers \(u\) and \(v\), indicating a bidirectional road between cities \(u\) and \(v\).
The following \(Q\) lines each contain four integers: \(S_i\), \(E_i\), \(L_i\) and \(R_i\), representing a trip from city \(S_i\) to city \(E_i\) and the corresponding thresholds for that trip.
outputFormat
For each trip, output a single line with either YES
if the journey is possible under the given constraints, or NO
otherwise.
sample
5 4 3
0 1
1 2
2 3
3 4
2 4 1 3
1 2 1 3
1 3 2 4
NO
YES
NO
</p>