QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100

#15758. 树

统计

带权树是指每条边都标有代表边长的数字的树。所有边长均为正数。对于每个节点,你需要求出其到树中其他节点的最大可能距离。

输入格式

输入包含对树的描述。

输入的第一行包含一个整数 $N$($2 \le N \le 50000$)。

接下来的 $N-1$ 行,每行包含一条树边的描述。每条边由三个正整数描述。前两个整数是该边连接的节点编号(范围从 $1$ 到 $N$),第三个数字是边的长度。

所有边的总长度不超过 $2^{31}-1$。保证输入包含对树的正确描述。

输出格式

输出恰好包含 $N$ 行:第 $k$ 行($k=1 \dots N$)包含从节点 $k$ 到最远节点的距离。

样例

输入样例 1

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

输出样例 1

5
9
10
10
8
6

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.