This page is still under construction.

Parts of this page are still being built. What you see may change.

Road

Time limit6sMemory limit1024 MB

Summary
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 nn cities in a country connected by mm bidirectional roads. The cities are numbered 1,2,…,n1, 2, \dots, n and the roads are numbered 1,2,…,m1, 2, \dots, m. Road ii connects city uiu_i and city viv_i, and its length is wiw_i 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 ll roads (a simple cycle is a cycle in which no city is visited twice except the start) may be written as c1→c2→⋯→cl−1→clc_1 \to c_2 \to \dots \to c_{l-1} \to c_l such that for all 1≤i<l1 \le i < l, city cic_i and city ci+1c_{i+1} are directly connected by a road, city c1c_1 and city clc_l are directly connected by a road, and for all 1≤i<j≤l1 \le i < j \le l, we have ci≠cjc_i \ne c_j. If l>3l > 3, 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 1≤u<v≤l1 \le u < v \le l with v−u≥2v-u \ge 2, where uu and vv are not 11 and ll at the same time, such that city cuc_u and city cvc_v are directly connected by a road.

The country plans to renovate the route between city ss and city tt. 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 nn and mm, the number of cities and the number of roads. Each of the next mm lines contains three integers uiu_i, viv_i, and wiw_i, the endpoints and length of road ii. Each road connects two different cities. The last line contains two integers ss and tt, 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 −1-1.

Constraints

For all test cases, 2≤n≤5×1052 \le n \le 5 \times 10^5, 2≤m≤1062 \le m \le 10^6, s≠ts \ne t, 1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i, and 1≤wi≤1091 \le w_i \le 10^9. No two roads have the same pair of endpoints. The roads satisfy the conditions stated in the problem.

Examples2

  1. Example 1

    Input
    4 5
    1 2 1
    2 3 1
    3 4 1
    1 3 5
    2 4 6
    1 4
    
    Expected output
    6
    
  2. Example 2

    Input
    2 1
    1 2 1
    1 2
    
    Expected output
    -1