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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 whose shortest distances from vertices are all equal. Among such vertices minimize the largest shortest distance from to every location. Output if impossible.
Input
followed by weighted undirected roads.
Output
Print the optimum or -1.
Subtasks
- Subtask 1 (40 points): ; ; ; ; .
- Subtask 2 (60 points): ; ; ; .
Examples
Input
6 5
1 6 1
2 6 1
3 6 1
4 6 1
5 6 1
Output
1
Explanation
Vertex has distance from each of vertices through and is at distance at most from all vertices.