PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT0000131. Người đặc biệt (Special Students)

Bài tập này chưa được xếp vào lộ trình.

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 NN students, of whom SS are already special before any recorded message is exchanged. A non-special student becomes special once they have communicated with at least KK distinct special students, at least once with each. Every message between two students counts as communication in both directions.

Son has a record of MM 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 N,K,S,MN,K,S,M.
  • The second line contains SS names of initially special students, separated by spaces.
  • Each of the next MM lines contains two names of students who exchanged a message. Each name consists of at most 1010 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): K=1K=1; 1≤S≤N≤1001\le S\le N\le100; 1≤M≤10001\le M\le1000; each name consists of 11–1010 lowercase letters and names are distinct; no self-messages.
  • Subtask 2 (40 points): 1≤K≤S≤N≤10001\le K\le S\le N\le1000; 1≤M≤100001\le M\le10000; each name consists of 11–1010 lowercase letters and names are distinct; no self-messages.
  • Subtask 3 (30 points): 1≤K≤S≤N≤100001\le K\le S\le N\le10000; 1≤M≤1000001\le M\le100000; each name consists of 11–1010 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 K=1K=1 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 K=2K=2. 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 55.