Two robots start at given stations and cover opposite ends of one trunk pipe, minimizing the slower robot travel time.
Medium6Shortest pathDFSGraphNo attempts yetTime limit2sMemory limit256 MBA country runs a huge oil transportation system. The system is built from control stations, and some pairs of stations are joined by pipes.
The system is connected, so there is a route along pipes from every control station to every other one. Some pipes break the connection the moment they fail: once such a pipe is gone, the system is no longer connected. A pipe like that is called a trunk pipe. At least one trunk pipe exists.
The company bought two robots to service trunk pipes. When the command arrives, one trunk pipe is chosen and the two robots set off for opposite ends of that pipe, one robot to each end. The arrival time is the time taken by the robot that reaches its end later.
Robots travel along pipes and cover one unit of length in one unit of time. At the moment the command arrives, the two robots stand at the given control stations. The two stations may be the same or different.
Write a program that picks a trunk pipe whose arrival time is as small as possible.
The first line contains the number of control stations N and the number of pipes M. (2≤N≤100000, 2≤M≤100000)
Each of the next M lines contains three integers: the numbers of the two control stations that the pipe joins, and the length of that pipe. Station numbers run from 1 to N, and a length is between 1 and 1000. Several pipes may join the same pair of stations, and no pipe joins a station to itself.
The last line contains the numbers of the two control stations where the robots stand when the command arrives.
The system is connected and it has at least one trunk pipe.
Print the smallest possible arrival time of the robots on one line.