QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#14524. Planting Trees

Statistiques

Siri and her teammates are participating in the preliminary round of the China Collegiate Planting Competition (CCPC). The preliminary round requires a greening project in the city: planting trees in the residential districts of the city.

The city consists of $n$ districts, numbered $1 \sim n$. There are $n - 1$ bidirectional roads connecting the districts, ensuring that all districts are reachable from each other. Before the competition begins, Siri learns that some districts do not need any more trees planted, while the tree-planting tasks for all remaining districts must be completed by Siri and her teammates.

As is well known, CCPC is a competition for teams of three. To perform at their best, Siri and her teammates decide to work together. Each day, they choose a connected component of size 3 and spend one day completing the tree-planting tasks in these 3 districts. Long-term work requires a balance of work and rest. Therefore, at least one of the three districts chosen for work each day must have already had its tree-planting task completed before that day.

Siri wants to know the minimum number of days required to complete the CCPC preliminary round.

Input

The first line contains an integer $T$ ($1 \le T \le 10^5$), representing the number of test cases.

For each test case, the first line contains two integers $n, m$ ($1 \le m \le n$, $3 \le n \le 10^5$, $1 \le \sum n \le 10^6$), representing the number of districts in the city and the number of districts where the tree-planting task has already been completed, respectively.

The second line contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le n$, all $a_i$ are distinct), representing the indices of the districts where the tree-planting task is already completed.

The next $n - 1$ lines each contain two integers $u, v$ ($1 \le u, v \le n$, $u \neq v$), representing a bidirectional road.

Output

For each test case, output a single integer representing the answer.

Examples

Input 1

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

Output 1

1
2
2
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.