War
Limits: 4 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Once upon a time in a galaxy far, far away, the peaceful country of 47-land was attacked by the hostile 66-land. 47-land has \(n\) cities. The cities of 47-land are connected by roads in such a way that you can get from any city to any other city using the existing roads in the country. Also, there is only one path between each pair of cities. Before the hostilities began, all cities were controlled by 47-land.
During the war, 47-land either lost control of some cities or recaptured them. In order to finally end this war, General Petro needs your help. The war has been going on for \(q\) days. It is known that on the \(i\)-th day of the war, city \(x_i\) came under the control of the other country. For example, if the city was controlled by 47-land, now it will be controlled by 66-land, and vice versa.
Help Petro by telling him the number of regions in 47-land on the \(i\)-th day, as this will help Petro devise a strategy to defeat the occupying country. Two cities \(a\) and \(b\) are considered to be in the same region if there is a path between them that passes through cities controlled by 47-land.
Input
The first line contains two integers \(n\) and \(q\) — the number of cities in 47-land and the number of days the war lasts, respectively.
The next \(n-1\) lines contain two integers \(u\) and \(v\) — the roads between the cities.
The next \(q\) lines contain a single integer \(x_i\) — the city where the controlling country changed on the \(i\)-th day of the war.
Output
Print the answer to the problem in \(q\) lines. In the \(i\)-th line, print a single number — the number of regions of 47-land after the \(i\)-th day of the war.
Constraints
\(1 \le n, q \le 10^{5}\),
\(1 \le u, v, x_i \le n\),
Problem evaluation consists of the following blocks:
1 point — example from the statement,
9 points — a block of tests in which \(1 \le n, q \le 10^{3}\),
15 points — a block of tests in which \(1 \le n, q \le 10^{5}\),
Points for a block will be awarded only if you give the correct answer to all tests in the block.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 7 3 1 2 1 3 3 4 4 5 3 6 6 7 3 6 7 | 3 3 2 |
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|