Time limit: 2 seconds Memory limit: 256 MB Source: 2nd Preliminary Exam of the 27th…
- User
Time limit: 2 seconds Memory limit: 256 MB Source: 2nd Preliminary Exam of the 27th Computer Olympiad Sabira lives in Kazakhstan. The country consists of n n cities numbered 0 0 to n −1 n−1, connected by m m two-way roads. The i i-th road connects the two cities u i u i and v i v i . Christmas is coming and she wants to visit her relatives.
She lives in the city x x; her paternal relatives live in the city y y and her maternal relatives live in the city z z. She wants to go from her city x x to her father's relatives' city y y and then to her mother's relatives' city z z for a vacation and finally return to her home in city x x.
Due to heavy snowfall and Sabira's unfamiliarity with the roads, crossing the i i-th road for the first time will take a i a i minutes and subsequent times (independent of the direction of travel on the road) will take b i b i minutes ( a i ≥ b i a i ≥b i ).
Sabira wants to spend the least amount of time on the roads in order to be with her relatives more. Find the least amount of time spent on the roads.
Input The first line of the input contains two numbers n n and m m.
In the next line, there are three numbers x x, y y, and z z, respectively.
In the i ith line of the next m m line, there are four numbers u i u i , v i v i , a i a i , and b i b i , respectively. 3 ≤ n ≤ 500 3≤n≤500 2 ≤ m ≤ n × ( n − 1 ) 2 2≤m≤ 2 n×(n−1)
0 ≤ x , y , z < n 0≤x,y,z<n 0≤u i , v i < n 0≤u i ,v i <n 0≤ b i ≤ a i ≤ 1 0 9 0≤b i ≤a i ≤10 9
No road connects a city to itself.
There is at most one road between any two cities.
The three cities x x, y y, and z z are different.
It is guaranteed that there is a path from x x to y y and from x x to z z.
Output Print the shortest possible travel time on the only line of output.
Subproblems Subproblem Score Constraints 1 14 There is exactly one road route between any two of the n n cities in Kazakhstan 2 19 a i
b i a i =b i
3 67 No additional constraints Example Input Sample 1 5 6 0 1 2 0 1 20 15 0 3 7 2 3 4 4 4 4 1 10 5 4 2 15 15 2 3 14 13 Plain text Output Sample 1 57 Plain text In the above example, the optimal traversal order of the cities is 0 , 3 , 4 , 1 , 4 , 2 , 3 , 0 0,3,4,1,4,2,3,0 c++
- Assistant