問題一覧 > 通常問題

No.3222 Let the World Forget Me

レベル : / AI推定難易度 : 1300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 53
作問者 : nauclhlt / テスター : Cafe1942
お気に入りにしたユーザー ProblemId : 12457 / 自分の提出
問題文最終更新日: 2026-10-20 09:11:55
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 476 (順位表) の他の問題:

Story

"May the world... please forget me..."

Problem Statement

There is a tree with $N$ vertices, numbered $1, 2, \cdots, N$. The $i$-th edge connects vertex $A_i$ and vertex $B_i$.

Each vertex has a value called its purity; the purity of vertex $i$ is $P_i$.

Currently, some vertices of this tree are contaminated. At time $0$, the contaminated vertices are the $M$ vertices $C_1, C_2, \cdots, C_M$.

From now on, at each time represented as time $t$ for a positive integer $t$, the following event occurs.

  • Let $S$ be the set of vertices that are contaminated at that moment. For every $x\in S$, all vertices adjacent to vertex $x$ that are not yet contaminated become contaminated.

In addition, at each time represented as time $t-0.5$ for a positive integer $t$, you perform the following action.

  • If there exist vertices that are leaves and are not contaminated at that moment, choose the one with the maximum purity among them, and remove the chosen vertex and the $1$ edge coming out of it. If no such leaf exists, do nothing.

Find the sum of the purity over all vertices you remove at or before time $10^{100}$.

Input

$N\ M$
$P_1\ P_2\cdots\ P_N$
$A_1\ B_1$
$A_2\ B_2$
$\vdots$
$A_{N-1}\ B_{N-1}$
$C_1\ C_2\ \cdots\ C_M$
  • $2\leq N\leq 10^5$
  • $1\leq M\leq N$
  • $1\leq P_i\leq 10^9$
  • $P_1, P_2, \cdots, P_N$ are pairwise distinct.
  • $1\leq A_i, B_i\leq N$
  • $1\leq C_i\leq N$
  • The values in $C$ are pairwise distinct.
  • All input values are integers.

Output

Let $S$ be the sum of the purity over all vertices you remove at or before time $10^{100}$. Output it on one line in the following format.

$S$

Print a newline at the end.

Sample

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

The process proceeds as follows.

  • Time $0.5$: Remove vertex $5$.
  • Time $1$: Vertices $2$ and $3$ become newly contaminated.
  • Time $1.5$: Remove vertex $4$.
  • Time $2$ and later: Since all vertices are contaminated, no vertex becomes newly contaminated and no vertex can be removed.

Therefore, the answer is $P_5+P_4=6$.

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