CF1795F.Blocking Chips
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree, consisting of n vertices. There are k chips, placed in vertices a1,a2,…,ak. All ai are distinct. Vertices a1,a2,…,ak 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 i-th move (1-indexed) you are going to move the ((i−1)modk+1)-st chip from its current vertex to an adjacent white vertex and color that vertex black. So, if k=3, you move chip 1 on move 1, chip 2 on move 2, chip 3 on move 3, chip 1 on move 4, chip 2 on move 5 and so on. If there is no adjacent white vertex, then the game ends.
What's the maximum number of moves you can perform?
你被给定一棵包含 n 个顶点的树。有 k 个棋子,分别放置在顶点 a1,a2,…,ak 上。所有 ai 互不相同。初始时,顶点 a1,a2,…,ak 被染成黑色,其余顶点为白色。
你将进行一场游戏,执行若干次(可能为零次)操作。在第 i 次操作(从 1 开始编号)中,你将移动编号为 ((i−1)modk+1) 的棋子:将其从当前所在顶点移至一个相邻的白色顶点,并将该目标顶点染成黑色。例如,若 k=3,则你在第 1 次操作中移动第 1 个棋子,第 2 次操作中移动第 2 个棋子,第 3 次操作中移动第 3 个棋子,第 4 次操作中再次移动第 1 个棋子,第 5 次操作中再次移动第 2 个棋子,依此类推。若当前棋子所在顶点没有相邻的白色顶点,则游戏结束。
你最多能执行多少次操作?
输入格式
The first line contains a single integer t (1≤t≤104) — the number of testcases.
The first line of each testcase contains a single integer n (1≤n≤2⋅105) — the number of vertices of the tree.
Each of the next n−1 lines contains two integers v and u (1≤v,u≤n) — the descriptions of the edges. The given edges form a tree.
The next line contains a single integer k (1≤k≤n) — the number of chips.
The next line contains k integers a1,a2,…,ak (1≤ai≤n) — the vertices with the chips. All ai are distinct.
The sum of n over all testcases doesn't exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)——树的顶点数。
接下来的 n−1 行,每行包含两个整数 v 和 u(1≤v,u≤n)——边的描述。所给边构成一棵树。
下一行包含一个整数 k(1≤k≤n)——筹码的数量。
再下一行包含 k 个整数 a1,a2,…,ak(1≤ai≤n)——放置筹码的顶点。所有 ai 互不相同。
所有测试用例的 n 之和不超过 2⋅105。
输出格式
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
输入解题思路,AI测评打分。不知道怎么写?