問題一覧 > 通常問題

No.2618 Exorcism

レベル : / AI推定難易度 : 1750 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 57
作問者 : startcpp / テスター : 👑 Kazun
お気に入りにしたユーザー ProblemId : 7738 / 自分の提出
問題文最終更新日: 2024-01-26 12:59:26
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 416 (順位表) の他の問題:

Problem Statement

Start City has $N$ towns and $N - 1$ roads.
Road $i$ connects town $A_i$ and town $B_i$ bidirectionally, and it is possible to travel between any $2$ towns by following some roads.

Now, at night in Start City, ghosts appear in $M$ towns $V_1, \cdots, V_M$.

Each ghost casts an area spell and
plays pranks on all towns reachable from the town where it appeared by following $0$ or $1$ roads.

Cleaning up after the pranks is a lot of work, so it was decided to perform an exorcism.
When an exorcism is performed in town $v$ ($1 \le v \le N$),
a spell is cast that annihilates the ghosts that appeared in towns reachable from town $v$ by following $0$ or $1$ roads.
Ghosts hit by this spell can no longer play pranks on any town.

The exorcism is hard work, so it can be performed only $1$ time. Therefore, the choice of the town in which to perform it is an important matter.
For each of $v = 1, 2, \cdots, N$, find the number of towns on which pranks are played if the exorcism is performed in town $v$.

Input

$N$
$A_1$ $B_1$
$\cdots$
$A_{N-1}$ $B_{N-1}$
$M$
$V_1 \dots V_M$
  • All inputs are integers
  • It is possible to reach any $2$ towns from each other by following some roads
  • $2 \le N \le 200000$
  • $1 \le A_i \le N, 1 \le B_i \le N$
  • $1 \le M \le N$
  • $1 \le V_1 \lt V_2 \lt \cdots \lt V_M \le N$

Output

On line $i$ ($1 \le i \le N$), output the number of towns on which pranks are played if the exorcism is performed in town $i$.

Sample

Sample 1
Input
6
1 2
2 3
3 4
3 5
5 6
3
2 3 6
Output
5
2
2
5
3
5

In Sample 1, ghosts appear in towns $2, 3, 6$. If no exorcism is performed, pranks are played on the towns shown in yellow (in this case, all towns).

If the exorcism is performed in town $3$, the ghosts appearing in towns $2, 3$ are annihilated, and only the ghost in town $6$ can play pranks.
In this case, the towns on which pranks are played are towns $5, 6$, so there are $2$ of them.
Note that although town $5$ is within the range of the exorcism, pranks by ghosts that are not annihilated cannot be nullified.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。