Codeforces Round 977 (Div. 2, based on COMPFEST 16 - Final Round)
E3
Digital Village (Extreme Version)
Codeforces
2800
原题
← E2→
翻译中…

This is the extreme version of the problem. In the three versions, the constraints on $n$ and $m$ are different. You can make hacks only if all the versions of the problem are solved.

翻译中…

Pak Chanek is setting up internet connections for the village of Khuntien. The village can be represented as a connected simple graph with $n$ houses and $m$ internet cables connecting house $u_i$ and house $v_i$, each with a latency of $w_i$.

翻译中…

There are $p$ houses that require internet. Pak Chanek can install servers in at most $k$ of the houses. The houses that need internet will then be connected to one of the servers. However, since each cable has its latency, the latency experienced by house $s_i$ requiring internet will be the maximum latency of the cables between that house and the server it is connected to.

翻译中…

For each $k = 1,2,\ldots,n$, help Pak Chanek determine the minimum total latency that can be achieved for all the houses requiring internet.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains 3 integers $n$, $m$, $p$ ($2 \le n \le 2 \cdot 10^5$; $n-1 \le m \le 2 \cdot 10^5$; $1 \le p \le n$) — the number of houses, the number of cables, and the number of houses that need internet.

翻译中…

The second line of each test case contains $p$ integers $s_1, s_2, \ldots, s_p$ ($1 \le s_i \le n$) — the houses that need internet. It is guaranteed that all elements of $s$ are distinct.

翻译中…

The $i$-th of the next $m$ lines of each test case contains three integers $u_i$, $v_i$, and $w_i$ ($1 \le u_i \lt v_i \le n$; $1 \le w_i \le 10^9$) — the internet cable connecting house $u_i$ and house $v_i$ with latency of $w_i$. It is guaranteed that the given edges form a connected simple graph.

翻译中…

It is guaranteed that the sum of $n$ and the sum of $m$ do not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output $n$ integers: the minimum total latency that can be achieved for all the houses requiring internet for each $k = 1,2,\ldots,n$.

翻译中…

Note

翻译中…

In the first test case for $k=3$, a possible optimal solution is to install servers at vertices $2$, $6$ and $8$ and obtain the following latency:

翻译中…
  • $\text{latency}(2) = 0$
  • $\text{latency}(5) = \max(3, 5) = 5$
  • $\text{latency}(6) = 0$
  • $\text{latency}(8) = 0$
  • $\text{latency}(9) = \max(2, 4) = 4$
翻译中…

So the total latency is $9$.

翻译中…

样例

Input #1
2
9 8 5
2 5 6 8 9
1 2 1
1 3 2
3 4 10
4 5 3
4 6 5
1 7 10
7 8 4
7 9 2
3 3 2
3 1
1 2 1
2 3 3
1 3 2
Output #1
34 19 9 4 0 0 0 0 0
2 0 0
InputCopy OutputCopy
题目信息
题号
2021E3
时间限制
2 s
内存限制
256 MB
标签
数据结构
DFS 及类似
动态规划
并查集
图论
贪心
数学
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。