Cutting edges one at a time

Delete edges of a weighted undirected graph one by one so that the total weight removed before s and t get disconnected is as large as possible.

Hard8GraphMinimum spanning treeGreedySortingNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given an undirected graph with nn vertices and mm edges. Every edge has a weight. You take edges from the edge list one at a time and delete them from the graph, in whatever order you like.

The moment two vertices ss and tt become disconnected, you stop deleting. Disconnected means there is no way to walk from one of them to the other along the remaining edges.

Choose the deletion order so that the total weight of the edges deleted up to the moment you stop is as large as possible. Print that maximum.

Input

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

Each of the next mm lines has three integers aa, bb, cc, meaning the graph has 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 has two vertices ss and tt. (1s,tn1 \le s, t \le n, sts \ne t)

The edge list may hold more than one edge between the same pair of vertices. At the start ss and tt are always connected.

Output

Print on one line the maximum total weight of the edges deleted up to the moment ss and tt become disconnected.