#Lutece0746. Longest Common Path
Longest Common Path
Migrated from Lutece 746 Longest Common Path
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Per and Pal are friends, and like to hang out together. They are also very impatient, so they always take the shortest possible way when they need to go somewhere.
It's the end of the school day, and they need to go home.Naturally, they want to arrive at home as early as possible. They also want to maximize the time they walk together while walking towards their homes. You have been asked to write a computer program that calculates the maximal time they can walk together. Their neighbourhood is modelled as a graph where intersections are nodes and roads are edges.The roads are bidirectional, and it takes the same time to traverse a road in both directions. All important destinations happen to be located at an intersection. Also,the school and the two homes are never located at the same intersection. There exists a path between every pair of intersections.
Input
The first line of the input consists of a single integer , the number of test cases. The next line contains two integers and , the number of intersections and the number of bidirectional roads in the city, respectively. The following line contains three integers and , indicating the position of the school, Per's home and Pal's home, respectively. The next lines contain three integers and , indicating that there is a bidirectional road between intersections and which takes minutes to traverse. All intersections are numbered from to , inclusive.
Output
For each test case, output the length of the longest distance Per and Pal can walk together while still arriving at their own homes as fast as possible.
Samples
Note
Resources
IDI Open Programming Contest April 21st, 2012 - NTNU