luogu#P5235. [WC2017] 棋盘
[WC2017] 棋盘
Problem Description
Xiao Z is playing a game on a chessboard. This chessboard is an undirected connected graph with vertices and edges. The vertices are labeled with positive integers in . At the beginning of the game, each vertex has one piece placed on it. Each piece has an integer in , representing the piece’s label. All piece labels are distinct.
In each operation, Xiao Z must first choose an edge of the graph such that one endpoint of this edge currently has the piece labeled . Then, Xiao Z swaps the pieces on the two endpoints of this edge.
Now you are given the graph (the chessboard) and the initial label of the piece on each vertex. Xiao Z asks you to answer queries. Each query specifies a target state of the chessboard. You need to determine whether it is possible, using some number of operations, to transform the chessboard from the initial state into the target state.
Input Format
The first line contains three positive integers , representing the number of vertices, the number of edges, and the number of queries.
The next lines each contain two integers , indicating an undirected edge connecting vertices and . It is guaranteed that , so there are no self-loops. It is guaranteed that the given graph is connected, i.e., any two vertices can reach each other through some edges.
The next line contains space-separated integers. The -th integer denotes the label of the piece on vertex in the initial state. It is guaranteed that all labels are integers in and are pairwise distinct.
The next lines each contain space-separated integers describing one query. The -th integer denotes the label of the piece on vertex in the target state. It is guaranteed that all labels are integers in and are pairwise distinct.
Output Format
Output lines. Each line contains a string Yes or No. Yes means the target state in the query can be reached from the initial state using some number of operations, and No means it is impossible. Note that the first letter of both Yes and No is uppercase.
5 6 3
2 1
4 5
3 5
3 4
2 3
1 3
1 2 3 4 0
0 1 2 3 4
2 1 0 4 3
4 3 0 1 2
Yes
Yes
No
Hint
The samples are shown in the figure:

For the first query, it is enough to move the piece labeled along the path . For the second query, move the piece labeled along . The third query has no solution.
All testdata satisfy: , , .
| Test Point ID | Data Property | ||
|---|---|---|---|
| 1 | None | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | Property 1 | ||
| 6 | |||
| 7 | None | ||
| 8 | |||
| 9 | Property 2 | ||
| 10 | |||
| 11 | Property 3 | ||
| 12 | |||
| 13 | |||
| 14 | None | ||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 |
- Property 1: The degree of every vertex is .
- Property 2: This chessboard can be drawn on a rectangular grid graph, where and .
- Property 3: Each edge belongs to at most one simple cycle.
Translated by ChatGPT 5