4899 - 树的最长路径(最远点对)
Time Limit : 1 秒
Memory Limit : 128 MB
给定一棵树,树中包含 n 个结点(编号1~n)和 n−1 条无向边,每条边都有一个权值。现在请你找到树中的一条最长路径。 换句话说,要找到一条路径,使得使得路径两端的点的距离最远。注意:路径中可以只包含一个点。
Input
第一行包含整数 n。 接下来 n−1 行,每行包含三个整数 a b c
Output
输出一个整数,表示树的最长路径的长度。
Examples
Input
10 2 8 5 1 10 5 3 5 6 6 2 8 6 3 8 7 2 5 3 4 3 7 9 6 10 3 8
Output
40
Hint
数据范围 1 ≤ n ≤ 10000 1 ≤ a i , b i ≤ n -1e5<=ci<=1e5