#CT0000131. Người đặc biệt (Special Students)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Người đặc biệt (Special Students)
Special Students
Source: Bộ Giáo dục và Đào tạo
Version: Phuoc Hung OJ Extended
Problem Statement
A school has students, of whom are already special before any recorded message is exchanged. A non-special student becomes special once they have communicated with at least distinct special students, at least once with each. Every message between two students counts as communication in both directions.
Son has a record of messages exchanged between pairs of students, but does not know their actual chronological order. We may choose an ordering of these messages that maximizes the eventual number of special students.
Determine the maximum possible number of special students and output all their names in increasing lexicographical order. Students who appear neither in the initial special list nor in any recorded message never need to appear in the output. All student names are unique, and no message is exchanged with oneself.
Input
- The first line contains four integers .
- The second line contains names of initially special students, separated by spaces.
- Each of the next lines contains two names of students who exchanged a message. Each name consists of at most lowercase Latin letters
a–z.
Output
- The first line contains the maximum possible number of special students.
- The second line lists their names in increasing lexicographical order, separated by spaces.
Subtasks
- Subtask 1 (30 points): ; ; ; each name consists of – lowercase letters and names are distinct; no self-messages.
- Subtask 2 (40 points): ; ; each name consists of – lowercase letters and names are distinct; no self-messages.
- Subtask 3 (30 points): ; ; each name consists of – lowercase letters and names are distinct; no self-messages.
Examples
Example 1
Input
3 1 1 1
cuoi
son cuoi
Output
2
cuoi son
Explanation: Initially only cuoi is special. Since and son exchanges a message with cuoi, son also becomes special. The third student cannot be reached using the recorded messages.
Example 2
Input
9 2 3 6
san son rong
cuoi phuong
son anh
son cuoi
cuoi san
son phuong
san phan
Output
5
cuoi phuong rong san son
Explanation: Initially san, son, and rong are special and . Student cuoi has communicated with both son and san, and becomes special. Then phuong has communicated with son and cuoi, and also becomes special. anh and phan each have only one special contact, so the final total is .
Liên quan
Trong các cuộc thi sau: