luogu#P5235. [WC2017] 棋盘

[WC2017] 棋盘

Problem Description

Xiao Z is playing a game on a chessboard. This chessboard is an undirected connected graph with nn vertices and mm edges. The vertices are labeled with positive integers in [1,n][1,n]. At the beginning of the game, each vertex has one piece placed on it. Each piece has an integer in [0,n1][0,n-1], 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 00. 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 qq 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 n,m,qn,m,q, representing the number of vertices, the number of edges, and the number of queries.

The next mm lines each contain two integers u,v(1u,vn)u,v(1\leq u,v\leq n), indicating an undirected edge connecting vertices uu and vv. It is guaranteed that uvu\neq v, 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 nn space-separated integers. The ii-th integer denotes the label of the piece on vertex ii in the initial state. It is guaranteed that all labels are integers in [0,n1][0,n-1] and are pairwise distinct.

The next qq lines each contain nn space-separated integers describing one query. The ii-th integer denotes the label of the piece on vertex ii in the target state. It is guaranteed that all labels are integers in [0,n1][0,n-1] and are pairwise distinct.

Output Format

Output qq 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 00 along the path 543215-4-3-2-1. For the second query, move the piece labeled 00 along 531235-3-1-2-3. The third query has no solution.

All testdata satisfy: 1n501 \leq n \leq 50, 1m1001 \leq m \leq 100, 1q10001 \leq q \leq 1000.

Test Point ID nn mm Data Property
1 8\leq 8 15\leq 15 None
2 =n1 = n-1
3 50\leq 50
4 =n =n
5 Property 1
6
7 None
8
9 100 \leq 100 Property 2
10
11 Property 3
12
13
14 None
15
16
17
18
19
20
  • Property 1: The degree of every vertex is 22.
  • Property 2: This chessboard can be drawn on a k×kk \times k rectangular grid graph, where k×k=nk \times k=n and 2k×(k1)=m2k \times (k-1)=m.
  • Property 3: Each edge belongs to at most one simple cycle.

Translated by ChatGPT 5