#K45442. Max Distance from the Capital

    ID: 27754 Type: Default 1000ms 256MiB

Max Distance from the Capital

Max Distance from the Capital

You are given a connected tree with n cities numbered from 1 to n and n-1 roads. City 1 is the capital. Each road connects two cities u and v and has a positive integer length l.

Your task is to calculate the maximum distance a message has to travel from the capital (city 1) to reach any other city. Formally, if you define the distance from the capital to a city along the unique path in the tree, you must determine:

[ \max_{2\le i\le n} {d(1,i)} ]

where d(1,i) is the sum of the lengths of the roads on the unique simple path from city 1 to city i.

Input Format: The first line contains an integer n denoting the number of cities. Each of the following n-1 lines contains three space-separated integers u, v, and l, describing a road.

Output Format: Output a single integer, the maximum distance from the capital to any city.

inputFormat

The input is read from stdin and has the following format:

n
u1 v1 l1
...
un-1 vn-1 ln-1

Here, n is the number of cities and each of the next n-1 lines contains three integers representing a road between city u and city v with length l.

outputFormat

Print a single integer to stdout — the maximum distance from the capital (city 1) to any other city.

## sample
5
1 2 4
1 3 2
3 4 8
3 5 3
10