PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000013. Sáu bậc quan hệ (Degrees of Separation)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Sáu bậc quan hệ (Degrees of Separation)
Degrees of Separation
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Undirected relationships form an unweighted graph. Find the largest shortest number of hops among all pairs; print DISCONNECTED if any pair cannot be connected.
Input
followed by pairs of single-token names.
Output
Print the network diameter or DISCONNECTED.
Subtasks
- Subtask 1 (40 points): ; ; .
- Subtask 2 (60 points): ; .
Examples
Input
3 2
Ana Ben
Ben Cam
Output
2
Explanation
Ana and Cam are separated by two relationships via Ben, so the network diameter is .