#P5663. Raw Material Supply

    ID: 18891 Type: Default 1000ms 256MiB

Raw Material Supply

Raw Material Supply

There is a factory with (n) workers labeled from (1) to (n). Between some pairs of workers there is a bidirectional conveyor belt, and there is at most one belt between any two workers.

When a worker (x) initiates the production of a part processed to stage (L) (with (L > 1)), all workers directly connected to (x) by a belt are forced to produce a part processed to stage (L-1) (but (x) itself does not produce the part with stage (L-1)).

If a worker (x) initiates the production of a part processed to stage (1), then all workers directly connected to (x) must supply one unit of raw material for (x).

Worker 1 (Xuanxuan) is curious: given (q) work orders, where the (i)-th order means that worker (a_i) wants to produce a part processed to stage (L_i), does worker 1 need to supply raw material for that order?

A careful analysis shows that, under the production rules, a worker (v) will be forced to produce a part if and only if there is a simple path from the initiating worker (a) to (v) with length (d) such that the part produced is of stage (L - d) (and production only occurs if (L-d\ge 1)). In particular, a worker will produce a part with stage (1) if and only if its distance from (a) is exactly (L-1). Hence, worker 1 is required to supply raw material if and only if there exists a worker (x) (with (x \neq 1)) that produces a stage (1) part and is directly connected to worker 1. In an undirected graph, note that if (a\ne1) then one can always choose the neighbor of worker 1 lying on a shortest path from (a) to 1. Consequently, worker 1 supplies raw material if and only if (a \neq 1) and the distance from (a) to 1 is exactly (L) (since on the shortest path, the neighbor of 1 has distance (L-1)).

Your task is to answer each work order accordingly.

inputFormat

The first line contains three integers (n), (m) and (q) ((1 \le n \le 10^5,; 0 \le m \le 10^5,; 1 \le q \le 10^5)), representing the number of workers, the number of conveyor belts, and the number of work orders, respectively.

The next (m) lines each contain two integers (u) and (v) ((1 \le u,v \le n)) indicating a bidirectional conveyor belt between workers (u) and (v). It is guaranteed that there is at most one belt between any two workers.

Each of the following (q) lines contains two integers (a_i) and (L_i) ((1 \le a_i \le n,; 1 \le L_i \le 10^9)), meaning that worker (a_i) wants to produce a part processed to stage (L_i).

outputFormat

For each work order, print a line containing either “Yes” if worker 1 must supply raw material, or “No” otherwise.

Note: Even if worker 1 is forced to also produce a part for some work order, he still supplies raw material for any other worker producing a stage 1 part.

sample

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

Yes Yes

</p>