#P8602. [蓝桥杯 2013 省 A] 大臣的旅费
[蓝桥杯 2013 省 A] 大臣的旅费
Problem Description
A long time ago, the Kingdom of 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 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.
is an important minister of . He travels among the cities to observe people’s lives. Therefore, traveling nonstop from one city to another is what does most often. He has a money bag to store the travel expenses between cities.
The smart minister 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 kilometer from the -th kilometer to the -th kilometer (where is an integer), the expense is . That is, traveling kilometer costs , and traveling kilometers costs .
Minister 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 (), the number of cities in the Kingdom of , including the capital.
Cities are numbered from to , where city is the capital.
The next lines describe the expressways of (there are exactly expressways).
Each line contains three integers , indicating that there is an expressway between city and city with length () kilometers.
Output Format
Output one integer, the maximum travel expense that Minister may spend.
5
1 2 2
1 3 1
2 4 5
2 5 4
135
Hint
Sample explanation: Minister traveling from city to city costs .
Time limit: 5 seconds, 64 MB. Lanqiao Cup 2013, the 4th provincial contest.
Translated by ChatGPT 5