Ignition
Time limit1sMemory limit64 MB
Given a connected undirected weighted graph, choose a vertex to light so that the fire spreading along edges burns every point in the shortest total time.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Brute force, Math
- Solved
- No attempts yet
Problem
Seohun did badly on today's algorithms final and is in a foul mood. To work some of it off, he decides to set fire to the graph that appeared on the exam.

Seohun can light one vertex of the graph (the circles in the picture above). The moment a vertex catches fire, the fire spreads at once along every edge attached to that vertex. On an edge the fire advances 1 unit of distance per second. When fire enters one edge from both ends, the two flames burn toward each other and die out at the point where they meet.
The time to burn the graph is the time at which the last point of the graph burns. Pick the vertex to light so that this time is as small as possible. Ignore the places where edges cross in the picture above.
Input
The first line contains the number of vertices and the number of edges . (, )
Each of the next lines contains the two endpoints and of an edge and its length . (, )
An edge may have both endpoints at the same vertex, and two vertices may be joined by more than one edge. Every vertex can be reached from every other vertex along the edges.
Output
Print the minimum time needed to burn the whole graph, with one digit after the decimal point. The answer is always a multiple of , so no rounding error can appear and your output must match the answer exactly.
Hint
In the second example, lighting vertex 3 burns the graph fastest.