PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000038. Nhóm phương án liên thông (Test)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Nhóm phương án liên thông (Test)
Test
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Each record gives five alternatives and one chosen letter. Add directed edges from the chosen letter to each of the other five alternatives and output strongly connected letter groups.
Input
Integer , followed by lines of six uppercase letters: five alternatives and the selected answer as the sixth letter.
Output
Print each strongly connected component on its own line with alphabetically sorted letters, and sort components by their first letter.
Subtasks
- Subtask 1 (40 points): ; ; each letter belongs to
A–Z; repeated letters are allowed. - Subtask 2 (60 points): ; each letter belongs to
A–Z; repeated letters are allowed.
Examples
Input
4
A B C D E C
F C H I J J
K B H I F I
K C E B J K
Output
A
B
C
D
E
F
H
I J K
Explanation
Construct directed edges from the chosen letter (sixth character) to the five alternatives. Only I, J, K are mutually reachable; other active letters are singleton components.