PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000003. Rủi ro (Risk)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Rủi ro (Risk)
Risk
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are exactly countries, numbered through . Each bidirectional border crossing costs one move. Find minimum moves for the queried pairs.
Input
For each country , read followed by its neighbors; then and pairs.
Output
Print each result as u to v: d, with country IDs right-aligned to width two.
Subtasks
- Subtask 1 (40 points): ; ; ; ; .
- Subtask 2 (60 points): ; ; ; .
Examples
Input
1 2
2 1 3
2 2 4
2 3 5
2 4 6
2 5 7
2 6 8
2 7 9
2 8 10
2 9 11
2 10 12
2 11 13
2 12 14
2 13 15
2 14 16
2 15 17
2 16 18
2 17 19
2 18 20
2
1 20
3 3
Output
1 to 20: 19
3 to 3: 0
Explanation
The countries form the chain , so the distance from to is and from to itself is .