CF1119F.Niyaz and Small Degrees

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Niyaz has a tree with nn vertices numerated from 11 to nn. A tree is a connected graph without cycles.

Each edge in this tree has strictly positive integer weight. A degree of a vertex is the number of edges adjacent to this vertex.

Niyaz does not like when vertices in the tree have too large degrees. For each xx from 00 to (n−1)(n-1), he wants to find the smallest total weight of a set of edges to be deleted so that degrees of all vertices become at most xx.

尼亚兹有一棵包含 nn 个顶点的树,顶点编号从 11 到 nn。树是一种无环的连通图。

该树中的每条边都具有严格正整数的权重。一个顶点的度数是指与该顶点相邻的边的数量。

尼亚兹不喜欢树中顶点的度数过大。对于每个从 00 到 (n−1)(n-1) 的 xx,他希望找出需要删除的边的最小总权重,使得所有顶点的度数均不超过 xx。

输入格式

The first line contains a single integer nn (2≤n≤250 0002 \le n \le 250\,000) — the number of vertices in Niyaz's tree.

Each of the next (n−1)(n - 1) lines contains three integers aa, bb, cc (1≤a,b≤n1 \le a, b \le n, 1≤c≤1061 \leq c \leq 10^6) — the indices of the vertices connected by this edge and its weight, respectively. It is guaranteed that the given edges form a tree.

第一行包含一个整数 nn(2≤n≤250 0002 \le n \le 250\,000)—— 表示尼亚兹的树中的顶点数量。

接下来的 (n−1)(n - 1) 行中,每行包含三个整数 aa、bb、cc(1≤a,b≤n1 \le a, b \le n,1≤c≤1061 \leq c \leq 10^6)—— 分别表示该边所连接的两个顶点的编号及其权重。保证所给的边构成一棵树。

输出格式

Print nn integers: for each x=0,1,…,(n−1)x = 0, 1, \ldots, (n-1) print the smallest total weight of such a set of edges that after one deletes the edges from the set, the degrees of all vertices become less than or equal to xx.

输出 nn 个整数:对每个 x=0,1,…,(n−1)x = 0, 1, \ldots, (n-1),输出满足如下条件的边集的最小总权重——从图中删除该边集后,所有顶点的度数均不超过 xx。

输入输出样例

  • 输入#1

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

    输出#1

    10 6 3 1 0
  • 输入#2

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

    输出#2

    22 6 0 0 0

说明/提示

In the first example, the vertex 11 is connected with all other vertices. So for each xx you should delete the (4−x)(4-x) lightest edges outgoing from vertex 11, so the answers are 1+2+3+41+2+3+4, 1+2+31+2+3, 1+21+2, 11 and 00.

In the second example, for x=0x=0 you need to delete all the edges, for x=1x=1 you can delete two edges with weights 11 and 55, and for x≥2x \geq 2 it is not necessary to delete edges, so the answers are 1+2+5+141+2+5+14, 1+51+5, 00, 00 and 00.

在第一个例子中,顶点 11 与所有其他顶点相连。因此,对每个 xx,你需要删除从顶点 11 出发的最轻的 (4−x)(4-x) 条边,故答案依次为 1+2+3+41+2+3+4、1+2+31+2+3、1+21+2、11 和 00。

在第二个例子中,当 x=0x=0 时,你需要删除所有边;当 x=1x=1 时,你可以删除权重为 11 和 55 的两条边;而当 x≥2x \geq 2 时,则无需删除任何边,故答案依次为 1+2+5+141+2+5+14、1+51+5、00、00 和 00。

输入解题思路,AI测评打分。不知道怎么写?

首页