Adding edges one by one

Add the given weighted edges one at a time in any order and stop once s and t become connected; maximize the total weight of added edges at that moment.

Medium6Union-findGreedySortingGraphInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

You have an undirected graph with n vertices and no edges, plus a list of m 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 vertices s and t become connected. Two vertices are connected when you can walk from one to the other along edges.

Choose the order so that the total weight of the edges in the graph at the moment you stop is as large as possible. That total includes the weight of the last edge, the one that connected s and t. Print the largest total you can reach.

Input

The first line has the number of vertices n and the number of edges in the list m. (2n502 \le n \le 50, 1m10001 \le m \le 1000)

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

The last line has the two vertices s and t. (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 makes the graph connected.

Output

Print on the first line the largest possible total weight of the edges added up to the moment s and t become connected.