Aesthetic
Time limit2sMemory limit1024 MB
Given a connected weighted graph whose roads are ordered by aesthetics, pick one pair i<j that adds W_j to W_i, maximizing the shortest 1-to-N distance afterward.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path
- Solved
- No attempts yet
Problem
Syrup the Turtle lives in a town with a layout of locations connected by roads. Locations are numbered and roads are numbered . Road directly connects locations and , has length , and can be traveled in either direction. Any two locations can reach each other directly or indirectly, and no two roads share the same pair of endpoints.
Each road has its own scenery. The residents agree on how aesthetically pleasing each road is, and the roads become more aesthetic as the index grows, from road 1 to road .
The residents want to refine the town further. An identical copy of a more aesthetic road is built on top of a strictly less aesthetic road. Road can be copied onto road if and only if , and this changes the length of road to . The residents vote for exactly one pair of roads to carry out this project.
Syrup makes frequent trips between his house at location and the main square at location . Find the maximum possible length of the shortest path between locations and after the project is done.
Input
The first line contains and . Each of the next lines contains , , and , describing road .
Output
Print a single integer on one line: the maximum possible length of the shortest path between locations and after the project.
Constraints