CF1611E1.Escape The Maze (easy version)

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The only difference with E2 is the question of the problem..

Vlad built a maze out of nn rooms and n1n-1 bidirectional corridors. From any room uu any other room vv can be reached through a sequence of corridors. Thus, the room system forms an undirected tree.

Vlad invited kk friends to play a game with them.

Vlad starts the game in the room 11 and wins if he reaches a room other than 11 , into which exactly one corridor leads.

Friends are placed in the maze: the friend with number ii is in the room xix_i , and no two friends are in the same room (that is, xixjx_i \neq x_j for all iji \neq j ). Friends win if one of them meets Vlad in any room or corridor before he wins.

For one unit of time, each participant of the game can go through one corridor. All participants move at the same time. Participants may not move. Each room can fit all participants at the same time.

Friends know the plan of a maze and intend to win. Vlad is a bit afraid of their ardor. Determine if he can guarantee victory (i.e. can he win in any way friends play).

In other words, determine if there is such a sequence of Vlad's moves that lets Vlad win in any way friends play.

输入格式

The first line of the input contains an integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases in the input. The input contains an empty string before each test case.

The first line of the test case contains two numbers nn and kk ( 1k<n21051 \le k < n \le 2\cdot 10^5 ) — the number of rooms and friends, respectively.

The next line of the test case contains kk integers x1,x2,,xkx_1, x_2, \dots, x_k ( 2xin2 \le x_i \le n ) — numbers of rooms with friends. All xix_i are different.

The next n1n-1 lines contain descriptions of the corridors, two numbers per line vjv_j and uju_j ( 1uj,vjn1 \le u_j, v_j \le n ) — numbers of rooms that connect the jj corridor. All corridors are bidirectional. From any room, you can go to any other by moving along the corridors.

It is guaranteed that the sum of the values nn over all test cases in the test is not greater than 21052\cdot10^5 .

输出格式

Print tt lines, each line containing the answer to the corresponding test case. The answer to a test case should be "YES" if Vlad can guarantee himself a victory and "NO" otherwise.

You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" will all be recognized as positive answers).

输入输出样例

  • 输入#1

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

    输出#1

    YES
    NO
    YES
    NO

说明/提示

In the first test case, regardless of the strategy of his friends, Vlad can win by going to room 44 . The game may look like this:

The original locations of Vlad and friends. Vlad is marked in green, friends — in red. Locations after one unit of time. End of the game.Note that if Vlad tries to reach the exit at the room 88 , then a friend from the 33 room will be able to catch him.

首页