Gold snack sticks on Cebu

Given a weighted undirected graph, find the maximum over all routes from s to e of the minimum edge weight on the route.

Medium6GraphUnion-findGreedyInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

Hyebin and Sungi took a trip to an island near Cebu. The island is a set of houses floating on the sea, joined by oak bridges. Sungi arranged a surprise event with the island keeper, who is keeping Hyebin at the event site.

On the day of the event Sungi wants to carry snack sticks made of gold to that site. Every bridge has a weight limit on how much can cross it at once. Throwing away expensive gold on the way would be a waste, so Sungi wants to leave home carrying exactly as many sticks as can reach Hyebin's house in one trip.

Sungi picks any route and may pass through the same house or the same bridge more than once. Whatever route is taken, the smallest weight limit among the bridges on that route decides how much can be carried at once. Given the house numbers and the weight limit of every bridge, find the largest number of gold sticks Sungi can bring to Hyebin.

One gold stick weighs 1, and Sungi's own weight is not counted.

Input

The first line has the number of houses NN (2N1000002 \le N \le 100\,000) and the number of bridges MM (1M3000001 \le M \le 300\,000).

The second line has the number of the house Sungi starts from, ss, and the number of the house Hyebin is in, ee. (1s,eN1 \le s, e \le N, ses \ne e)

Each of the next MM lines describes one bridge as a house number h1h_1 (1h1N1 \le h_1 \le N), a house number h2h_2 (1h2N1 \le h_2 \le N), and a weight limit kk (1k10000001 \le k \le 1\,000\,000), meaning house h1h_1 and house h2h_2 are joined by a bridge whose weight limit is kk. A bridge can be crossed in both directions.

Several bridges may join the same pair of houses, and a bridge with h1h_1 equal to h2h_2 may appear.

Output

Print on the first line the largest number of gold sticks that can be carried in one trip from Sungi's house to Hyebin's house. If no route joins the two houses, print 0.

Hint

In the first example the best route crosses 171 \to 7 (limit 4), 767 \to 6 (limit 4), and 656 \to 5 (limit 3). The amount this route carries at once is min(4,4,3)=3\min(4, 4, 3) = 3.