Road
Time limit6sMemory limit1024 MB
Find the minimum total length of a route from city s to city t whose roads can be removed while the remaining roads still connect all cities.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, DFS
- Solved
- No attempts yet
Problem
There are cities in a country connected by bidirectional roads. The cities are numbered and the roads are numbered . Road connects city and city , and its length is meters. Starting from any city, you may reach any other city via the roads.
The roads are built in a special way. Formally, a simple cycle passing through roads (a simple cycle is a cycle in which no city is visited twice except the start) may be written as such that for all , city and city are directly connected by a road, city and city are directly connected by a road, and for all , we have . If , the roads must also satisfy this condition: there exist two non-adjacent cities on the cycle that are directly connected by a road. In other words, there exists with , where and are not and at the same time, such that city and city are directly connected by a road.
The country plans to renovate the route between city and city . The route is closed during renovation, so the remaining roads must still let you reach every other city from any city. Find a possible route to renovate with the smallest total length.
Input
The first line contains two integers and , the number of cities and the number of roads. Each of the next lines contains three integers , , and , the endpoints and length of road . Each road connects two different cities. The last line contains two integers and , the endpoints of the route to be renovated.
Output
Print one integer, the minimum possible length of the route to be renovated that satisfies the conditions above. If no feasible route exists, print .
Constraints
For all test cases, , , , , , and . No two roads have the same pair of endpoints. The roads satisfy the conditions stated in the problem.