题目描述
Problem Description
During a treasure hunt game, Little G and Little H are exploring a series of $n$ rooms numbered $1, 2, \cdots, n$, with doors between adjacent rooms. Some of these doors are locked and require specific keys to open, while others can be opened directly. Little G informs Little H about where each key is located for each locked door (each lock has exactly one corresponding key). Little G then gives Little H $p$ instructions, each directing Little H to travel from room $S_i$ to room $T_i$. However, Little G might include dead ends in his instructions, and Little H wants to avoid unnecessary effort by checking if a path exists for each instruction beforehand.
Can you help Little H determine if a path exists for each instruction?
Input Format
The first line contains three numbers: $n, m, p$, representing the number of rooms, the number of locked doors, and the number of queries, respectively. The next $m$ lines each contain two numbers $x, y$, indicating that the key for the door between room $x$ and room $x+1$ is in room $y$. The following $p$ lines each contain two integers $S_i, T_i$, representing a query.
Output Format
Output $p$ lines, each containing either YES or NO, indicating whether a path exists or not.
Sample Input and Output
Sample Input #1
5 4 5
1 3
2 2
3 1
4 4
2 5
3 5
4 5
2 1
3 1
Sample Output #1
YES
NO
YES
YES
NO
Sample Input #2
7 5 4
2 2
3 3
4 2
5 3
6 6
2 1
3 4
3 7
4 5
Sample Output #2
YES
YES
NO
NO
Notes
$1 \le n, p \le 10^6$, $0 \le m < n$, $1 \le x, y, S_i, T_i < n$. It is guaranteed that $x$ values are unique.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分