This problem has three extra sample files you can refer to, each of which can be found here.
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 (here, a simple cycle means a cycle such that no
cities are visited twice except the start) may be represented as
such that for all
, city
and city
are
connected directly by a road, city
and city
are connected
directly by a road, and for all
, we have
. If
, then the roads satisfy the following
additional constraint: there exist two non-adjacent cities on the cycle
such that the two cities are directly connected by a road, or in other
words, there exists
such that
,
are not
and
simultaneously, and city
and city
are directly connected by a road.
Now the country is going to find a route to renovate between city
and city
. Since the road will be inaccessible during renovation, the
country wants to make sure it is possible to reach all other cities
starting from any city in the country via the remaining roads during
renovation (i.e. roads that are not included in the route to be
renovated).
Please find a possible route to renovate and make sure the length is as
short as possible.
Input Specification
The first line contains two integers
denoting the
number of cities and the number of roads. The following
lines
contain three integers
each denoting the endpoints of the
roads and the lengths. It is guaranteed that each road connects two
different cities, or in other words,
. The last line
contains two integers
denoting the endpoints of the route to be
renovated.
Output Specification
The output contains only one integer denoting the minimum
possible length of the route to be renovated satisfying the constraints
specified in the problem. If there are no feasible solutions, output -1
.
Sample Input 1
Copy
4 5
1 2 1
2 3 1
3 4 1
1 3 5
2 4 6
1 4
Sample Output 1
Copy
6
The route to be renovated is
.
Sample Input 2
Copy
2 1
1 2 1
1 2
Sample Output 2
Copy
-1
For all test cases,
,
,
,
,
,
.
It is guaranteed for any two roads their endpoints are not entirely the same.
It is guaranteed the roads satisfy the conditions specified in the problem.
Test Case |
 |
 |
Additional Constraints |
1~6 |
 |
 |
None. |
7~10 |
 |
 |
The roads have equal lengths. |
11~15 |
All roads satisfying form a path from to , and the endpoints of the roads with have distance 2 on the path. |
16~20 |
None. |
Comments