Query Jungle
시간 제한3초메모리 제한2048 MB
뿌리 있는 트리에서 일부 정점에 몬스터가 있고, 각 서브트리 뒤집기 질의 후 모든 몬스터를 덮는 뿌리 시작 경로의 최소 개수를 구한다. The answer for a set of marked vertices is the count of marked vertices whose parent is not marked. A subtree flip at v toggles this count for v and all its children. So maintain for each vertex a value d(u) = a[u] AND (1 - a[parent(u)]), where a[1] is treated as 1 for the root's contribution. The answer is the sum of d(u) over all u. Under a flip of subtree(v), a[v] toggles, a[parent(v)] toggles (if v is not root), and for every child c of v, a[parent(c)] = a[v] toggles. So d(v) toggles value, d(c) for each child togg
문제
Oner is a jungler --- a role where you hunt monsters in a jungle. Given the number of trees he sees in a jungle, it's no surprise that he is addicted to tree query problems.
You are given a tree of vertices, rooted at vertex . Each vertex either contains a monster or does not.
You want to find the minimum integer such that there exist paths that satisfy the following conditions:
- Each path must start at the root (vertex ).
- Every vertex with a monster must be included in at least one of these paths. A vertex is considered included in a path if it is one of the path's vertices, including its endpoints.
To make this problem more challenging, you must also answer queries. For each query, you are given a vertex . For each vertex in the subtree of , its status is inverted --- the one containing a monster starts to not contain one, and the one not containing a monster starts to contain one. After each query, you must solve the original problem again with the updated status.
Note that queries are cumulative, so the effects of each query carry on to future queries.
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line contains a single integer () --- the number of vertices in the tree.
The next line contains integers (), representing the initial status. If , vertex contains a monster; if , it does not.
The next lines each contain two integers and (), describing an edge between vertices and . It is guaranteed that these edges form a tree.
The next line contains a single integer () --- the number of queries.
The next lines each contain a single integer () --- the vertex given for the -th query.
It is guaranteed that the sum of over all test cases does not exceed .
It is guaranteed that the sum of over all test cases does not exceed .
출력
Print lines. The first line should contain the minimum number of paths for the initial status. Each subsequent line should contain the answer after each query.
힌트
Test Case 1:
Initial State: The monsters are in vertex . We need two paths: and . The answer is .
After Query 1 (): The monsters are in vertex . We only need one path, . The answer is .
After Query 2 (): The monsters are in vertex . We only need one path, . The answer is .
After Query 3 (): The monsters are in vertex . We need two paths, and . The answer is .
After Query 4 (): The monsters are in vertex . We need three paths, , , and . The answer is .
The following figure denotes the tree in the example input.

Test Case 2:
Initial State: The monsters are in vertex . We need one path: . The answer is .
After Query 1 (): There are no monsters. We need zero paths. The answer is .
After Query 2 (): The monsters are in vertex . We need one path: . The answer is .