#P5663. [CSP-J 2019] 加工零件

[CSP-J 2019] 加工零件

Description

Kaikai’s factory is producing a magical part in an orderly way, and of course the production process is also magical. There are nn workers in the factory, numbered from 1n1 \sim n. Between some pairs of workers, there are two-way conveyor belts for transporting parts. It is guaranteed that there is at most one conveyor belt between any two workers.

If worker xx wants to produce a part processed to stage L(L>1)L\,(L \gt 1), then all workers that are directly connected to worker xx by a conveyor belt need to produce a part processed to stage L1L - 1 (but worker xx himself/herself does not need to produce a stage L1L - 1 part).

If worker xx wants to produce a part processed to stage 11, then all workers that are directly connected to worker xx by a conveyor belt need to provide worker xx with one raw material.

Xuanxuan is worker 11. Now qq work orders are given. The ii-th work order means that the worker numbered aia_i wants to produce a part at stage LiL_i. For each work order, Xuanxuan wants to know whether he needs to provide raw materials for others. He knows that smart you can help him compute it.

Input Format

The first line contains three positive integers nn, mm, and qq, representing the number of workers, the number of conveyor belts, and the number of work orders.

The next mm lines each contain two positive integers uu and vv, indicating that there is a conveyor belt between worker uu and worker vv. It is guaranteed that uvu \neq v.

The next qq lines each contain two positive integers aa and LL, indicating that worker aa wants to produce a part at stage LL.

Output Format

Output qq lines, each containing a string Yes or No. If producing according to the ii-th work order requires Xuanxuan (worker 11) to provide raw materials, output Yes on the ii-th line; otherwise output No.

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

Hint

Sample 1 Explanation

If worker 11 wants to produce a stage 11 part, worker 22 needs to provide raw materials.

If worker 22 wants to produce a stage 11 part, workers 11 and 33 need to provide raw materials.

If worker 33 wants to produce a stage 11 part, worker 22 needs to provide raw materials.

If worker 11 wants to produce a stage 22 part, worker 22 needs to produce a stage 11 part, and workers 11 and 33 need to provide raw materials.

If worker 22 wants to produce a stage 22 part, workers 11 and 33 need to produce a stage 11 part, and both of them need worker 22 to provide raw materials.

If worker 33 wants to produce a stage 22 part, worker 22 needs to produce a stage 11 part, and workers 11 and 33 need to provide raw materials.

Sample 2 Explanation

If worker 11 wants to produce a stage 11 part, workers 22 and 55 need to provide raw materials.

If worker 11 wants to produce a stage 22 part, workers 22 and 55 need to produce a stage 11 part, and workers 1,3,41,3,4 need to provide raw materials.

If worker 11 wants to produce a stage 33 part, workers 22 and 55 need to produce a stage 22 part, workers 1,3,41,3,4 need to produce a stage 11 part, and workers 2,3,4,52,3,4,5 need to provide raw materials.

If worker 11 wants to produce a stage 44 part, workers 22 and 55 need to produce a stage 33 part, workers 1,3,41,3,4 need to produce a stage 22 part, workers 2,3,4,52,3,4,5 need to produce a stage 11 part, and all workers need to provide raw materials.

If worker 11 wants to produce a stage 55 part, workers 22 and 55 need to produce a stage 44 part, workers 1,3,41,3,4 need to produce a stage 33 part, workers 2,3,4,52,3,4,5 need to produce a stage 22 part, all workers need to produce a stage 11 part, and all workers need to provide raw materials.

Constraints

There are 2020 test points in total.

For all test points, it is guaranteed that 1u,v,an1 \leq u, v, a \leq n.

For test points 141\sim4, 1n,m10001 \leq n, m \leq 1000, q=3q = 3, L=1L = 1.

For test points 585\sim8, 1n,m10001 \leq n, m \leq 1000, q=3q = 3, 1L101 \leq L \leq 10.

For test points 9129\sim12, 1n,m,L10001 \leq n, m, L \leq 1000, 1q1001 \leq q \leq 100.

For test points 131613\sim16, 1n,m,L10001 \leq n, m, L \leq 1000, 1q1051 \leq q \leq 10^5.

For test points 172017\sim20, 1n,m,q1051 \leq n, m, q \leq 10^5, 1L1091 \leq L \leq 10^9.

Translated by ChatGPT 5