CF1790G.Tokens on Graph

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an undirected connected graph, some vertices of which contain tokens and/or bonuses. Consider a game involving one player — you.

You can move tokens according to the following rules:

  • At the beginning of the game, you can make exactly one turn: move any token to any adjacent vertex.
  • If the movement of the token ended on the bonus, then you are allowed to make another turn with any other token.

You can use different bonuses in any order. The same bonus can be used an unlimited number of times. Bonuses do not move during the game.

There can be several tokens in one vertex at the same time, but initially there is no more than one token in each vertex.

The vertex with number 11 is the finish vertex, and your task is to determine whether it is possible to hit it with any token by making turns with the tiles according to the rules described above. If a token is initially located at the vertex of 11 , then the game is considered already won.

The finish line is in black, the bonuses are in red, the chips are in grey. For example, for a given graph, you can reach the finish line with a chip from the 88 th vertex by making the following sequence of turns: 1. Move from the 88 -th vertex to the 66 -th.
2. Move from the 77 -th vertex to the 55 -th.
3. Move from the 66 -th vertex to the 44 -th.
4. Move from the 55 -th vertex to the 66 -th.
5. Move from the 44 -th vertex to the 22 -nd.
6. Move from the 66 -th vertex to the 44 -th.
7. Move from the 22 -nd vertex to the 11 -st vertex, which is the finish.

输入格式

The first line of input data contains a single integer tt ( 1t1041 \le t \le 10^4 ) — number of test cases in the test. The descriptions of the test cases follow.

The first line of the description of each test case contains two integers nn and mm ( 1n21051 \le n \le 2 \cdot 10^5 , 0m21050 \le m \le 2 \cdot 10^5 ) — the number of vertices and edges in the graph, respectively.

The second line of the description of each test case contains two integers pp and bb ( 1pn,0bn1 \le p \le n, 0 \le b \le n ) — the number of tokens and bonuses, respectively.

The third line of the description of each test case contains pp different integers from 11 to nn — the indices of the vertices in which the tokens are located.

The fourth line of the description of each input data set contains bb different integers from 11 to nn — the indices of the vertices in which the bonuses are located. Note that the value of bb can be equal to 00 . In this case, this line is empty.

There can be both a token and a bonus in one vertex at the same time.

The next mm lines of the description of each test case contain two integers uiu_i and viv_i ( 1ui,vin1 \le u_i, v_i \le n , uiviu_i \ne v_i ) — vertices connected by the ii -th edge. There is at most one edge between each pair of vertices. The given graph is connected, that is, from any vertex you can get to any one by moving along the edges.

The test cases are separated by an empty string.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 . Similarly, it is guaranteed that the sum of mm over all input data sets does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print YES in a separate line if you can reach the finish with some token, and NO otherwise.

You can output YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive response).

输入输出样例

  • 输入#1

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

    输出#1

    YES
    NO
    YES
    YES
    YES
    YES

说明/提示

  • The first test case is explained in the statement.
  • In the second test case, there is only one token which can make only one turn, and it cannot reach the finish.
  • In the third test case, the token can reach the finish line in 11 turn.
  • In the fourth test case, you need to make just one turn from 22 to 11 .
  • In the sixth test case, the token is initially at node number 11 , so we win immediately.
首页