Traveling Bloggers
Time limit3sMemory limit1024 MB
- Level
Not classified yet
- Solved
- No attempts yet
Statement
Yan and Tatyana decided to become travel bloggers and post videos about trips around the cities of their country.
The country has cities numbered from 1 to . City 1 is the capital. The cities are connected by two-way roads numbered from 1 to , and each road connects two different cities. The same pair of cities may be connected by several roads. From any city, you can reach every other city by road.
The travelers plan to leave the capital for some other city, but they have not chosen which one yet. A route to city consists of cities and roads such that:
- and .
- Road connects cities and .
- They do not drive the same road twice, so all are distinct. The route may pass through the same city several times, including city 1, where the trip starts, and city , where it ends.
For each road , the travelers computed the length of the video filmed along it, denoted .
During the trip, each traveler picks one road of the route and films a video about it. Yan likes short videos, so he picks the road with the smallest . Tatyana prefers long videos, so she picks the road with the largest .
The total length of the two videos is .
The travelers plan to upload to a platform where short videos are more popular, so they want to minimize the total length of the two videos. For each destination city , compute the minimum total length over all routes from city 1 to city .
Input
The first line contains two integers , (, ), the number of cities and roads.
Each of the next lines describes a road. The -th of these lines contains three integers , , (, , ), the numbers of the two cities the road connects and the video length for that road.
It is guaranteed that you can travel from any city to any other city using the given roads, possibly through other cities.
Output
For each , print the minimum total length of the two travelers' videos for a trip that ends in city .
Hint
In the first example, the possible optimal routes are:
- . The video lengths total .
- . The video lengths total .
In the second example, the possible optimal routes are:
- . The video lengths total .
- . The video lengths total .
- . The video lengths total .
- . The video lengths total .
- . The video lengths total .
- . The video lengths total .
In the third example, the possible optimal routes are:
- . The video lengths total .
- . The video lengths total .
- . The video lengths total .