PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000012. Xe buýt và số phận (Bus and Unavoidable Destiny)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xe buýt và số phận (Bus and Unavoidable Destiny)

Bus and Unavoidable Destiny

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Select a bus stop as home to minimize the maximum shortest travel time to every other stop, in a connected undirected bus network.

Input

n,mn,m followed by mm undirected routes u,v,wu, v, w.

Output

Print the minimum possible maximum travel time.

Subtasks

  • Subtask 1 (40 points): n≤8n\le 8; 2≤n≤3002\le n\le 300; n−1≤m≤44850n-1\le m\le 44850; 1≤w≤10001\le w\le 1000; 1≤u,v≤n1\le u,v\le n.
  • Subtask 2 (60 points): 2≤n≤3002\le n\le 300; n−1≤m≤44850n-1\le m\le 44850; 1≤w≤10001\le w\le 1000; 1≤u,v≤n1\le u,v\le n.

Examples

Input

3 2
1 2 10
2 3 10

Output

10

Explanation

At stop 22, the maximum shortest travel time is 1010; at either end stop it is 2020.