Chasing Game

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

Given an undirected connected graph with N vertices and M edges, Alice and Bob are playing a chasing game on the graph. The game is played for Q times with different starting positions.

In the i-th round, Alice starts at vertex a_i, and Bob starts at vertex b_i. Both players always know each other's current positions. The rules of the game are as follows:

  • The two players take turns, with Bob moving first in each round.
  • Bob can move along any number of edges (even 0, meaning he can stay in the current vertex) during his turn, but he cannot pass through the vertex where Alice currently is.
  • Alice can move along at most one edge (or stay in place) during her turn.
  • If Alice ends her move on the vertex where Bob currently is, Alice wins.

Alice tries her best to catch Bob to win the game, and Bob tries his best to avoid being caught forever. Your task is to determine, for each game, whether Alice can guarantee a win in finite moves, no matter how optimally Bob plays.

Input

The first line contains three integers N, M, Q (1 \le N, M, Q \le 10^5), the number of vertices, edges, and games respectively.

The next M lines each contain two integers u and v, (1 \le u, v \le N), indicating an undirected edge between vertices u and v. The graph is connected, no self-cycle, and there is at most one edge between a pair of vertices.

The next Q lines each contain two integers a and b, (1 \le a, b, \le N), representing Alice and Bob's starting positions in one game.

Output

Output Q lines. For each game, print Yes if Alice can guarantee a win in finite moves, otherwise print No.

Constraints

Subtask Points Additional constraints
1 10 N, M, Q \le 10
2 16 N, M, Q \leq 100
3 24 N, M, Q \leq 1\,000
4 16 M = N
5 34 No additional constraints

Sample Input

8 10 3
1 2
2 3
3 4
4 1
6 4
5 6
6 7
8 7
8 5
8 6
6 4
4 5
5 7

Sample Output

No
Yes
No

Explanation

The graph is shown as above.

  • For the 1st game, Alice starts from 6 and Bob starts from 4. Bob can move to the vertex 2. When Alice arrives at a vertex ajacent to 2, Bob can move to one of the vertices in [1, 2, 3, 4], which is not adjacent to Alice. Thus, Alice cannot reach Bob in finite moves.
  • For the 2nd game, when Alice moved to the vertex 6, she can catch Bob in one step, not matter Bob is at vertex 5, 7 or 8.

Comments

There are no comments at the moment.