Connecting Edges 2

Given a weighted edge list, pick the order of adding edges that makes the total weight added up to the moment s and t first become connected as small as possible.

Medium5GraphSortingDynamic programmingMinimum spanning treeInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

An undirected graph starts with nn vertices and 00 edges. You are given an edge list of mm weighted edges. You add the edges of the list to the graph one at a time, in any order you like, and you stop the moment vertex ss and vertex tt become connected. Two vertices are connected when you can travel from one to the other along edges.

Choose the order that makes the total weight of the added edges as small as possible at the moment ss and tt become connected, and report that minimum.

Input

The first line contains the number of vertices nn and the number of edges in the list mm. (2n50002 \le n \le 5000, 1m1000001 \le m \le 100000)

Each of the next mm lines contains three integers aa, bb, cc, meaning the list holds an edge of weight cc between vertex aa and vertex bb. (1a,bn1 \le a, b \le n, 1c1001 \le c \le 100, aba \ne b)

The last line contains the two vertices ss and tt. (1s,tn1 \le s, t \le n, sts \ne t)

The list may hold several edges between the same pair of vertices. Adding every edge of the list is guaranteed to make the graph connected.

Output

Print on the first line the minimum total weight of the edges added up to the moment ss and tt become connected.