PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000037. Các nhóm gọi điện (Calling Circles)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Các nhóm gọi điện (Calling Circles)
Calling Circles
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Partition people into strongly connected calling circles: within a circle every person can reach every other via directed calls.
Input
Integers , followed by directed calls .
Output
Print each group on its own line with names separated by comma-space; sort names within each group and groups by their first name.
Subtasks
- Subtask 1 (40 points): ; , ; exactly distinct names appear; alphabetic names at most 25 characters.
- Subtask 2 (60 points): , ; exactly distinct names appear; alphabetic names at most 25 characters.
Examples
Input
5 5
Ana Bao
Bao Chi
Chi Ana
Dao Em
Em Dao
Output
Ana, Bao, Chi
Dao, Em
Explanation
Ana, Bao, and Chi form one strongly connected component; Dao and Em form another. No pair from different components is mutually reachable.