#P14480. 化作彗星

    ID: 13403 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>洛谷原创O2优化构造洛谷月赛Ad-hoc

化作彗星

Description

To recreate the comet of that day, Nana and Lily need to use specific number pairs to transform one sequence into another.

Nana has a sequence aa of length nn. Lily can choose an index i(1i<n)i(1\le i<n) each time, and then operate aix,ai+1ya_i\leftarrow x,a_{i+1}\leftarrow y.

The chosen 1x,yk1\le x,y\le k must satisfy f(ai,ai+1)=f(x,y)=1f(a_i,a_{i+1})=f(x,y)=1. Lily finally needs to transform aa into another sequence bb of length nn.

Here, Nana will give an undirected graph GG with kk vertices and mm edges. It is not guaranteed that there are no multiple edges or self-loops. Then f(x,y)=1f(x,y)=1 if and only if there is an edge between xx and yy in the graph. Note that if there is a self-loop at xx (an edge from xx to xx), then f(x,x)=1f(x,x)=1; otherwise, f(x,x)=0f(x,x)=0.

Lily is not very concerned about the construction of the solution, so she wants you to answer for multiple test cases whether aa can be transformed into another sequence bb of length nn.

Input Format

Each data point starts with three integers m,k,Tm, k, T.

The first mm lines, the ii-th line has two integers xi,yix_i, y_i indicating the ii-th edge connects (xi,yi)(x_i,y_i).

Then, there are TT test cases.

Each test case input has three lines:

  • The first line is an integer nn.
  • The second line is a sequence aa of length nn, where the ii-th number is aia_i.
  • The third line is a sequence bb of length nn, where the ii-th number is bib_i.

Output Format

For each test case, output one line with a string. If it is possible to transform aa into bb, output YES; otherwise, output NO.

1 2 2
1 2
6
1 1 2 1 2 2
2 1 1 2 2 1
2
2 2
1 2

YES
NO

Hint

Sample Explanation

For the first sample, we can operate as follows:

  1. Choose i=2i=2, the sequence becomes [1,2,1,1,2,2][1,2,1,1,2,2].
  2. Choose i=1i=1, the sequence becomes [2,1,1,1,2,2][2,1,1,1,2,2].
  3. Choose i=4i=4, the sequence becomes [2,1,1,2,1,2][2,1,1,2,1,2].
  4. Choose i=5i=5, the sequence becomes [2,1,1,2,2,1][2,1,1,2,2,1].

For the second sample, clearly you cannot perform the first operation. So it is impossible.

Data Range

Subtask Data Range Special Constraints Score
11 n2n\le 2 The graph is connected 2525
22 n105n\le 10^5
33 The graph is a forest
44 None

This problem uses subtask bundling. You must pass all test points in a subtask to get the corresponding score.

For all data, 1T1041\le T\le 10^4, 2n1052\le n\le 10^5, n106\sum n\le 10^6, 1m3×1051\le m\le 3\times 10^5, 1k2×1051\le k\le 2\times 10^5.

It is guaranteed that 1ai,bi,xi,yik1\le a_i,b_i,x_i,y_i\le k. The graph is not guaranteed to be without multiple edges or self-loops.