#abc369g. G - As far as possible
G - As far as possible
Score : points
问题陈述
你得到了一个有 个顶点的树。顶点编号为 , , , 。 第 条边()连接顶点 和 ,长度为 。
对于每个 ,解决以下问题。
高桥和青木在玩一个游戏。游戏进行如下。
- 首先,青木在树上指定 个不同的顶点。
- 然后,高桥构建一条从顶点 开始并在顶点 结束的路径,并且通过青木指定的所有顶点。
分数定义为高桥构建的路径的长度。高桥想要最小化分数,而青木想要最大化它。当两个玩家都以最优方式玩时,找出分数。
路径的定义 在无向图(可能是树)上的路径是一系列 个顶点和 条边 (其中 是一个正整数),使得边 连接顶点 和 。同一个顶点或边可以在序列中多次出现。如果存在至少一个 ()使得 ,则路径通过顶点 。(可以有多个这样的 。)路径分别从 开始并在 结束,路径的长度是 , , , 的长度之和。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a tree with vertices. The vertices are numbered , , , .
The -th edge () connects vertices and , with a length of .
For each , solve the following problem.
Takahashi and Aoki play a game. The game proceeds as follows.
- First, Aoki specifies distinct vertices on the tree.
- Then, Takahashi constructs a walk that starts and ends at vertex , and passes through all the vertices specified by Aoki.
The score is defined as the length of the walk constructed by Takahashi. Takahashi wants to minimize the score, while Aoki wants to maximize it. Find the score when both players play optimally.
Definition of a walk A walk on an undirected graph (possibly a tree) is a sequence of vertices and edges (where is a positive integer) such that edge connects vertices and . The same vertex or edge can appear multiple times in the sequence. A walk is said to pass through vertex if there exists at least one () such that . (There can be multiple such .) The walk is said to start and end at and , respectively, and the length of the walk is the sum of the lengths of , , , .
Constraints
- All input values are integers.
- The given graph is a tree.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the problem for .
Sample Input 1
5
1 2 3
2 3 5
2 4 2
1 5 3
Sample Output 1
16
22
26
26
26
For , Aoki's optimal move is to specify vertex , and Takahashi's optimal move is to construct a path vertex vertex vertex vertex vertex , resulting in a score of .
For , Aoki's optimal move is to specify vertices and , and Takahashi's optimal move is to construct a path such as vertex vertex vertex vertex vertex vertex vertex , resulting in a score of .
For , the score when both players play optimally is .
Sample Input 2
3
1 2 1000000000
2 3 1000000000
Sample Output 2
4000000000
4000000000
4000000000
Beware that the answer may not fit in a -bit integer.