No.3113 The farthest point
問題文最終更新日: 2025-04-18 00:29:34
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
CPCTF 2025 : PPC
(順位表)
の他の問題:
Problem Statement
There is a tree $T$ with $N$ vertices, numbered from $1$ to $N$.
For $1 \leq i \leq N-1$, the $i$-th edge connects vertices $u_i$ and $v_i$ and has weight $w_i$.
Among the simple paths connecting any two vertices of $T$, output the largest value of the sum of the edge weights on the path.
Constraints
- $2 \leq N \leq 2 \times 10^5$
- $1 \leq u_i, v_i \leq N$
- $|w_i| \leq 10^9$
- The given graph is a tree.
- All input values are integers.
Input
The input is given from standard input in the following format.
$N$
$u_1$ $v_1$ $w_1$
$\vdots$
$u_{N-1}$ $v_{N-1}$ $w_{N-1}$
Output
Output the answer.
Sample
Sample 1
Input
2 1 2 100
Output
100
Sample 2
Input
2 1 2 -100
Output
0
Sample 3
Input
10 1 2 916904626 1 3 372928301 3 4 -110828955 3 5 62817969 6 1 526032989 3 7 799578709 8 3 735091801 9 1 905420374 10 3 1000000000
Output
2289832927
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。