#P4436. [HNOI/AHOI2018] 游戏
[HNOI/AHOI2018] 游戏
Description
Xiao G and Xiao H are playing a treasure-hunting game. There are rooms in a line, numbered , with a door between each pair of adjacent rooms. Some doors are locked (so they require the corresponding keys to open), and the remaining doors can be opened directly. Xiao G tells Xiao H which room contains the key for each lock (each lock has exactly one corresponding key), and then gives instructions: for the -th one, Xiao H is asked to go from room to room . However, Xiao G may intentionally include dead ends in the instructions, and Xiao H does not want to waste extra energy trying, so he wants to determine in advance whether a path exists for each instruction.
Can you answer for Xiao H?
Input Format
The first line contains three integers , representing that there are rooms, locked doors, and queries. The next lines each contain two integers , meaning that the key for the lock between rooms and is located in room . The next lines follow, where the -th line contains two integers , representing one query.
Output Format
Output lines, each containing YES or NO, indicating whether it is reachable.
5 4 5
1 3
2 2
3 1
4 4
2 5
3 5
4 5
2 1
3 1
YES
NO
YES
YES
NO
7 5 4
2 2
3 3
4 2
5 3
6 6
2 1
3 4
3 7
4 5
YES
YES
NO
NO
Hint

Constraints
, , . It is guaranteed that is not repeated.
Translated by ChatGPT 5
京公网安备 11011102002149号