#CSPJ2019D. 零件加工 (Parts Processing)

零件加工 (Parts Processing)

Description

Kaikai's factory is producing some kind of magical parts, and the production process of magical parts is, naturally, also magical. The factory has nn workers numbered from 11 to nn. There are bidirectional conveyor belts between some workers. It is guaranteed that there is at most one conveyor belt between any two workers.

If worker xx wants to produce a part that is in the LL-th stage (L>1L > 1) of production, all workers who are directly connected to worker xx via a conveyor belt have to produce a part that is in stage L1L - 1 (but worker xx doesn't need to produce a stage L1L - 1 part).

If worker xx wants to produce a part that is in stage 11 of production, all workers who are directly connected to worker xx via a conveyor belt have to provide worker xx with raw materials.

Xuan Xuan is worker 11. Given qq work orders, the ii-th work order is represented by two numbers aia_i and LiL_i denoting that worker aia_i wants to produce a part in stage LiL_i of production. Xuan Xuan wants to know whether he needs to provide raw materials to others for each work order. He knows that you are smart and can help him figure it out!

Input Format

The first line contains three positive integers n,mn, m and qq - the number of workers, the number of conveyor belts, and the number of work orders respectively.

Each of the next mm lines contains two integers uu and vv (uvu \neq v) denoting that there is a conveyor belt between the workers uu and vv.

Each of the next qq lines contains two positive integers aa and LL denoting that worker aa wants to produce a part in stage LL.

Output Format

For each work order print a single line containing Yes if Xuan Xuan needs to provide raw materials for that work order, and No otherwise.

3 2 6
1 2
2 3
1 1
2 1
3 1
1 2
2 2
3 2
No
Yes
No
Yes
No
Yes

For the first work order, worker 1 wants to produce a stage 1 part, so worker 2 needs to provide raw materials.

For the second work order, worker 2 wants to produce a stage 1 part, so workers 1 and 3 need to provide raw materials.

For the third work order, worker 3 wants to produce a stage 1 part, so worker 2 needs to provide raw materials.

For the fourth work order, worker 1 wants to produce a stage 2 part, so worker 2 needs to produce a stage 1 part, and workers 1 and 3 need to provide raw materials.

For the fifth work order, worker 2 wants to produce a stage 2 part, so workers 1 and 3 need to produce a stage 1 part, and both of them need worker 2 to provide raw materials.

For the sixth work order, worker 3 wants to produce a stage 2 part, so worker 2 needs to produce a stage 1 part, and workers 1 and 3 need to provide raw materials.

5 5 5
1 2
2 3
3 4
4 5
1 5
1 1
1 2
1 3
1 4
1 5
No
Yes
No
Yes
Yes

For the first work order, worker 1 wants to produce a stage 1 part, so workers 2 and 5 need to provide raw materials.

For the second work order, worker 1 wants to produce a stage 2 part, so workers 2 and 5 need to produce a stage 1 part, and workers 1, 3 and 4 need to provide raw materials.

For the third work order, worker 1 wants to produce a stage 3 part, so workers 2 and 5 need to produce a stage 2 part, workers 1, 3 and 4 need to produce a stage 1 part, and workers 2, 3, 4 and 5 need to provide raw materials.

For the fourth work order, worker 1 wants to produce a stage 4 part, so workers 2 and 5 need to produce a stage 3 part, workers 1, 3 and 4 need to produce a stage 2 part, workers 2, 3, 4 and 5 need to produce a stage 1 part, and all workers need to provide raw materials.

For the fifth work order, worker 1 wants to produce a stage 5 part, so workers 2 and 5 need to produce a stage 4 part, workers 1, 3 and 4 need to produce a stage 3 part, workers 2, 3, 4 and 5 need to produce a stage 2 part, all workers need to produce a stage 1 part, and all workers need to provide raw materials.

Constraints

There are a total of 20 tests.
1u,v,an1 \le u, v, a \le n
Tests 141 \sim 4: 1n,m1000,q=3,L=11 \le n, m \le 1000, q = 3, L = 1
Tests 585 \sim 8: 1n,m1000,q=3,1L101 \le n, m \le 1000, q = 3, 1 \le L \le 10
Tests 9129 \sim 12: 1n,m,L1000,1q1001 \le n, m, L \le 1000, 1 \le q \le 100
Tests 131613 \sim 16: 1n,m,L1000,1q1051 \le n, m, L \le 1000, 1 \le q \le 10^5
Tests 172017 \sim 20: 1n,m,q105,1L1091 \le n, m, q \le 10^5, 1 \le L \le 10^9