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

#FW0000016. Cuộc tấn công Orc (The Orc Attack)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cuộc tấn công Orc (The Orc Attack)

The Orc Attack

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Select a vertex xx whose shortest distances from vertices 1,2,3,4,51,2,3,4,5 are all equal. Among such vertices minimize the largest shortest distance from xx to every location. Output −1-1 if impossible.

Input

n,mn,m followed by mm weighted undirected roads.

Output

Print the optimum or -1.

Subtasks

  • Subtask 1 (40 points): n≤8n\le 8; 5≤n≤1005\le n\le 100; 0≤m≤200000\le m\le 20000; 1≤u,v≤n1\le u,v\le n; 1≤w≤1000001\le w\le 100000.
  • Subtask 2 (60 points): 5≤n≤1005\le n\le 100; 0≤m≤200000\le m\le 20000; 1≤u,v≤n1\le u,v\le n; 1≤w≤1000001\le w\le 100000.

Examples

Input

6 5
1 6 1
2 6 1
3 6 1
4 6 1
5 6 1

Output

1

Explanation

Vertex 66 has distance 11 from each of vertices 11 through 55 and is at distance at most 11 from all vertices.