QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 64 MB 満点: 100 ハック可能 ✓

#7211. 攻击

統計

Bobo 居住在一个由 $n$ 个城市组成的国家,城市编号为 $1, 2, \dots, n$。第 $i$ 个城市居住着 $a_i$ 名公民。国家有 $(n-1)$ 条道路,保证了任意两个城市之间都可以通过道路互相到达。

Bobo 获悉一些恐怖分子计划袭击他的国家。恐怖分子有 $q$ 种可能的袭击计划,其中第 $i$ 种计划是摧毁 $k_i$ 条编号为 $c_{i,1}, c_{i,2}, \dots, c_{i,k_i}$ 的道路。显而易见,袭击后国家会被分割成 $(k_i + 1)$ 个区域。对于由城市集合 $R = \{r_1, r_2, \dots, r_m\}$ 组成的区域,将选择城市 $h \in R$ 作为总部,以最小化 $\sum_{j=1}^m a_{r_j} \cdot \delta(h, r_j)$,其中 $\delta(i, j)$ 是从城市 $i$ 到城市 $j$ 所需的最少道路数。如果存在平局,则选择编号较小的城市。

Bobo 想知道每种计划下各个区域的总部编号。

输入格式

第一行包含两个整数 $n, q$ ($2 \le n \le 2 \times 10^5, 1 \le q \le 2 \times 10^4$)。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$)。

接下来的 $(n-1)$ 行中,第 $i$ 行包含两个整数 $s_i, t_i$ ($1 \le s_i, t_i \le n$),表示连接城市 $s_i$ 和 $t_i$ 的第 $i$ 条道路。

最后 $q$ 行中,第 $i$ 行包含一个整数 $k_i$ 和 $k_i$ 个不同的整数 $c_{i,1}, c_{i,2}, \dots, c_{i,k_i}$ ($1 \le k_i \le 10, 1 \le c_{i,j} \le n-1$)。

输出格式

对于每种计划,输出一行,包含 $(k_i + 1)$ 个整数 $h_1, h_2, \dots, h_{k_i+1}$,表示袭击后各区域的总部编号,按升序排列。

样例

样例输入 1

5 2
1 1 1 1 1
1 2
1 3
2 4
2 5
1 1
4 1 2 3 4

样例输出 1

1 2
1 2 3 4 5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.