| FIICode2023 |
|---|
| Закончено |
Since hiring Jonathans is expensive, the city council decided to turn off all the lights.
The city's lights are in the form of a tree of size $$$N$$$. A tree is an undirected graph with exactly one simple path between each pair of vertices.
The lights are to be turned off in order $$$a_1, a_2, ..., a_N$$$, where $$$a_i$$$ $$$(1 \leq i \leq N)$$$ represents the index of the light bulb to be turned off at time $$$i$$$. You have to find, for each $$$i$$$, the maximum length of a simple path consisting only of lit nodes.
* The length of a path is defined as the number of nodes it contains.
The first line contains an integer $$$N$$$ $$$(1 \leq N \leq 2 \cdot 10^5)$$$ - the number of nodes of the tree.
Each of the next $$$N - 1$$$ lines contains two integers $$$u$$$ and $$$v$$$ $$$(1 \leq u, v \leq N; u \neq v)$$$ denoting there is an undirected edge between node $$$u$$$ and node $$$v$$$. It is guaranteed that the given edges form a tree.
The following line will contain $$$N$$$ integers, the values $$$a_1, a_2, ..., a_N$$$.
The output should contain $$$N$$$ integers, representing the length of the longest path containing only lit nodes after turning off the lightbulbs $$$a_1, a_2, ... a_i$$$.
3 2 1 2 3 1 2 3
2 1 0
8 3 7 7 8 4 8 5 7 6 5 3 2 6 1 4 3 7 5 1 6 2 8
6 5 3 2 1 1 1 0
In the first example, after turning off node $$$1$$$, we have the longest path $$$[2, 3]$$$. After turning off $$$2$$$, the longest path consists only of node $$$3$$$. After turning off the last bulb, there is no path left, so the answer is $$$0$$$.
| Название |
|---|


