#P7353. Tom and Jerry's Chase on Graphs

    ID: 20551 Type: Default 1000ms 256MiB

Tom and Jerry's Chase on Graphs

Tom and Jerry's Chase on Graphs

Given an undirected connected graph with \(n\) vertices and \(m\) edges, Tom and Jerry play \(q\) rounds of a chase game. In the \(i\)-th game, Tom starts at vertex \(a_i\) and Jerry starts at vertex \(b_i\) (both players always know each other’s positions).

The rules are as follows:

  • Jerry and Tom take turns moving, with Jerry moving first.
  • In his turn, Jerry may traverse an arbitrary number of edges (or choose not to move) along the graph, but his movement path cannot pass through the vertex where Tom is currently located.
  • In his turn, Tom may move along at most one edge (or stay at his current vertex).
  • If after Tom's move he lands on the same vertex as Jerry, then Tom wins the game.

Assuming that Tom tries his best to capture Jerry as soon as possible and Jerry tries to prolong the game indefinitely, determine for each game whether Tom can guarantee a win within a finite number of moves.

Note: It turns out that this problem is equivalent to determining whether the given graph is cop-win in the classic Cops and Robber game. In a cop-win graph, a single cop (Tom) can always catch the robber (Jerry) regardless of the initial positions. Otherwise, Jerry can evade capture forever.

The closed neighborhood of a vertex \(u\) is defined as \(N[u] = \{u\} \cup \{v \mid (u,v) \text{ is an edge}\}\). A vertex \(u\) is said to be dominated by vertex \(v\) (\(u \neq v\)) if \(N[u] \subseteq N[v]\). A graph is cop-win if and only if it is possible to sequentially remove a vertex that is dominated by some other vertex until only one vertex remains. In this problem, if such a dismantling order exists, Tom can guarantee a win (output "YES"); otherwise, the answer is "NO".

inputFormat

The input begins with a line containing three integers \(n\), \(m\), and \(q\) \( (1 \leq n, m, q \leq \text{limits})\), representing the number of vertices, edges, and games respectively.

Then \(m\) lines follow, each containing two integers \(u\) and \(v\) \( (1 \leq u, v \leq n)\) indicating there is an undirected edge between vertices \(u\) and \(v\). It is guaranteed that the graph is connected.

After that, \(q\) lines follow. The \(i\)-th of these lines contains two integers \(a_i\) and \(b_i\) \( (1 \leq a_i, b_i \leq n)\) indicating the starting vertices of Tom and Jerry in the \(i\)-th game.

outputFormat

For each game, output a single line containing either "YES" if Tom can guarantee a win in a finite number of moves, or "NO" if Jerry can evade capture indefinitely.

Note: In a graph that is cop-win, Tom has a winning strategy regardless of the starting positions \(a_i\) and \(b_i\). Otherwise, if the graph is not cop-win, Jerry can always avoid capture.

sample

3 2 2
1 2
2 3
1 3
2 3
YES

YES

</p>