Bronze Cow Party
InterviewTime limit1sMemory limit128 MB
Given a connected undirected weighted graph, find twice the largest shortest-path distance from a fixed farm X, which is the longest round trip any cow makes.
- Level
Medium4 of 10
- Topics
- Shortest path, Graph, Heap, Greedy
- Solved
- No attempts yet
Problem
There are farms (), numbered through . From each farm, exactly one cow travels to a big cow party held at farm (). The farms are connected by bidirectional roads (); it is always possible to travel between any two farms along the roads. Traversing road takes () units of time. Two farms may be directly connected by more than one road.
After every cow has gathered at farm , they realize that each of them left her party favors back home. They pause the party and send every cow home to fetch her favors and then return to farm . Each cow walks the fastest possible route to her home farm and back. The party stays paused until the last cow returns, so its suspension time equals the largest round-trip time among all the cows. What is this minimum suspension time?
Input
The first line contains three space-separated integers , , and .
Each of the next lines describes one road with three space-separated integers , , and : road connects farms and and takes units of time to traverse.
Output
Print one integer: the minimum amount of time the party must be suspended.
Hint
Because the roads are bidirectional, a cow's round trip to farm and back takes exactly twice the shortest distance between her farm and farm . So compute the shortest distance from farm to every farm with a single shortest-path search, then double the largest of those distances.