Lining up Children | 프로그래밍의 벗 PivotOJ
PivotOJ

Lining up Children

시간 제한: 1000ms메모리 제한: 1024MB출처: EIO 2018-19 prelimBOJ 29942

문제

After a field trip, the teacher needs to line up all children in order to count them and verify that none are missing. Anyone who has ever had to deal with children knows how difficult this can be. A child absolutely must stand next to each of their friends, otherwise a riot will soon occur.

Find one possible way to order the children such that all children are satisfied.

입력

The first line of input contains two space-separated integers NN and MM---the number of children and the number of pairs who are friends (1N1051 \le N \le 10^5, 1M31051 \le M \le 3 \cdot 10^5).

The next line contains NN space-separated strings---the names of the children. Names are at most 10 symbols long and consist of only uppercase and lowercase Latin letters and dashes. It is guaranteed that each child has a name different from the rest.

Then follow MM lines, each containing two space-separated names, denoting a pair of friends.

출력

The first line of output should contain SAAB if a solution is possible, or EI SAA, if it is not. If a solution is possible, output on the second line the list of names in an order that would satisfy all children.

예제

예제 1

입력
5 3
Bob Carol Eve Dave Alice
Alice Carol
Alice Bob
Dave Eve
출력
SAAB
Bob Alice Carol Eve Dave

예제 2

입력
3 3
Regina Gretchen Karen
Regina Gretchen
Gretchen Karen
Regina Karen
출력
EI SAA
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.