Logo
(追記) (追記ここまで)

9491번 - Politics 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
15 초 256 MB148814650.000%

문제

You are helping a political party canvass their members. The party has a list of candidates they wish to support, and they also have a list of members, each of which supports one candidate.

The party wants for you to sort the list of members, according to some rules. You will be given the list of candidates, in the desired order. Then, you’ll have access to a list of supporters; each supporter will have one candidate that they support.

The party wants you to put the list of supporters in order, sorted by their preferred candidate. There may be some supporters who support the same candidate. If so, order them in the order that they appear on the original list. Some supporters may have a ‘write-in’ candidate, thereby mentioning a candidate who was not on the original preferred candidate list. Put these supporters at the end, grouped by candidate, in the order that their candidates appear in the list of supporters. There also may be candidates who have no supporters. They will probably be taken off the list later, but that’s just the politics of the situation.

입력

There will be several test cases in the input. Each test case will begin with a line with two integers, n (1≤n≤1,000) and m (1≤m≤100,000), where n is the number of candidates, and m is the number of supporters. On the following n lines will be the names of the candidates, one per line. These names will each be a single word consisting of from 1 to 30 capital letters. All n listed candidate names in any test case will be unique. After the candidates, the next m lines will describe the supporters, one per line. Each of these lines will contain two words separated with a single space. Each word contains from 1 to 30 capital letters. The first word is the name of the supporter, and the second is the name of the candidate that they support. The input will end with a line with two 0s.

출력

For each test case, print out the names of the supporters, one name per line, in the requested order. Do not output any spaces. Do not separate answers with a blank line.

제한

예제 입력 1

3 5
STEVENS
MICHAELS
JORDAN
BOB JORDAN
JACK STEVENS
MACK MICHAELS
BILL JORDAN
CHRIS MATTHEWS
1 5
FRED
SAM FRED
ARTHUR GEORGE
DANIEL HERBERT
MARK GEORGE
MIKE HERBERT
0 0

예제 출력 1

JACK
MACK
BOB
BILL
CHRIS
SAM
ARTHUR
MARK
DANIEL
MIKE

힌트

출처

ICPC > Regionals > North America > Southeast USA Regional > 2013 Southeast USA Regional Programming Contest > Division 2 G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /