#P4436. [HNOI/AHOI2018] 游戏

    ID: 3374 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2018各省省选安徽湖南枚举,暴力剪枝强连通分量,缩点

[HNOI/AHOI2018] 游戏

Description

Xiao G and Xiao H are playing a treasure-hunting game. There are nn rooms in a line, numbered 1,2,,n1,2,\cdots,n, 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 pp instructions: for the ii-th one, Xiao H is asked to go from room SiS_i to room TiT_i. 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 n,m,pn, m, p, representing that there are nn rooms, mm locked doors, and pp queries. The next mm lines each contain two integers x,yx, y, meaning that the key for the lock between rooms xx and x+1x+1 is located in room yy. The next pp lines follow, where the ii-th line contains two integers Si,TiS_i, T_i, representing one query.

Output Format

Output pp 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

1n,p1061 \le n, p \le 10^6, 0m<n0 \le m < n, 1x,y,Si,Ti<n1 \le x, y, S_i, T_i < n. It is guaranteed that xx is not repeated.

Translated by ChatGPT 5