#P8602. [蓝桥杯 2013 省 A] 大臣的旅费

[蓝桥杯 2013 省 A] 大臣的旅费

Problem Description

A long time ago, the Kingdom of TT was extremely prosperous. To better manage the country, the kingdom built many expressways to connect the capital with major cities.

To save money, the ministers of TT designed an excellent construction plan so that every major city can be reached from the capital either directly or indirectly through other major cities. Also, if you do not pass through any major city more than once, then the route from the capital to each major city is unique.

JJ is an important minister of TT. He travels among the cities to observe people’s lives. Therefore, traveling nonstop from one city to another is what JJ does most often. He has a money bag to store the travel expenses between cities.

The smart minister JJ found that if he does not stop to rest in any city, then during continuous traveling, the expense he pays depends on the distance he has already traveled. For the 11 kilometer from the (x1)(x - 1)-th kilometer to the xx-th kilometer (where xx is an integer), the expense is x+10x + 10. That is, traveling 11 kilometer costs 1111, and traveling 22 kilometers costs 2323.

Minister JJ wants to know: starting from some city and arriving at another city without resting in between, among all possible travel expenses, what is the maximum?

Input Format

The first line contains an integer nn (n105n \le 10^5), the number of cities in the Kingdom of TT, including the capital.

Cities are numbered from 11 to nn, where city 11 is the capital.

The next n1n - 1 lines describe the expressways of TT (there are exactly n1n - 1 expressways).

Each line contains three integers Pi,Qi,DiP_i, Q_i, D_i, indicating that there is an expressway between city PiP_i and city QiQ_i with length DiD_i (Di1000D_i \le 1000) kilometers.

Output Format

Output one integer, the maximum travel expense that Minister JJ may spend.

5
1 2 2
1 3 1
2 4 5
2 5 4
135

Hint

Sample explanation: Minister JJ traveling from city 44 to city 55 costs 135135.

Time limit: 5 seconds, 64 MB. Lanqiao Cup 2013, the 4th provincial contest.

Translated by ChatGPT 5