CF1795F.Blocking Chips

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a tree, consisting of nn vertices. There are kk chips, placed in vertices a1,a2,,aka_1, a_2, \dots, a_k . All aia_i are distinct. Vertices a1,a2,,aka_1, a_2, \dots, a_k are colored black initially. The remaining vertices are white.

You are going to play a game where you perform some moves (possibly, zero). On the ii -th move ( 11 -indexed) you are going to move the ((i1)modk+1)((i - 1) \bmod k + 1) -st chip from its current vertex to an adjacent white vertex and color that vertex black. So, if k=3k=3 , you move chip 11 on move 11 , chip 22 on move 22 , chip 33 on move 33 , chip 11 on move 44 , chip 22 on move 55 and so on. If there is no adjacent white vertex, then the game ends.

What's the maximum number of moves you can perform?

输入格式

The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of testcases.

The first line of each testcase contains a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the number of vertices of the tree.

Each of the next n1n - 1 lines contains two integers vv and uu ( 1v,un1 \le v, u \le n ) — the descriptions of the edges. The given edges form a tree.

The next line contains a single integer kk ( 1kn1 \le k \le n ) — the number of chips.

The next line contains kk integers a1,a2,,aka_1, a_2, \dots, a_k ( 1ain1 \le a_i \le n ) — the vertices with the chips. All aia_i are distinct.

The sum of nn over all testcases doesn't exceed 21052 \cdot 10^5 .

输出格式

For each testcase, print a single integer — the maximum number of moves you can perform.

输入输出样例

  • 输入#1

    5
    5
    1 2
    2 3
    3 4
    4 5
    1
    3
    5
    1 2
    2 3
    3 4
    4 5
    2
    1 2
    5
    1 2
    2 3
    3 4
    4 5
    2
    2 1
    6
    1 2
    1 3
    2 4
    2 5
    3 6
    3
    1 4 6
    1
    1
    1

    输出#1

    2
    0
    1
    2
    0
首页