시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB23131055.556%

문제

You are on vacation in a foreign country. This country has a local football league, and you don't know any of the team names. However, you have found a table of all the results from this season, and next to every match is the concatenated names of the two teams that played.

There are $n$ teams in total, named $s_1, s_2, \cdots, s_n$. You are given the concatenation $s_i+s_j$ for every ordered pair $i \neq j$. Find the teams names $s_1, s_2, \cdots, s_n$. Team names must be nonempty, but they do not need to be distinct.

입력

The first line of input contains the integer $n$ ($2 \leq n \leq 500$).

The following $n$ lines each contain $n$ strings, the table of concatenated team names. The $j$:th string on the $i$:th of these lines will contain the string $s_i + s_j$ if $i \neq j$, and "*" if $i = j$. The concatenated team names will consist of lower case characters a-z.

The total number of characters in concatenated team names is at most $10^6$.

출력

If there is no solution, print "NONE".

If there is more than one solution, print "MANY".

If there is one unique solution, print "UNIQUE", followed by $n$ lines containing $s_1, s_2, \cdots, s_n$.

예제 입력 1

3
* difaik difhammarby
aikdif * aikhammarby
hammarbydif hammarbyaik *

예제 출력 1

UNIQUE
dif
aik
hammarby

예제 입력 2

2
* aaaa
aaaa *

예제 출력 2

MANY

예제 입력 3

3
* a ab
a * b
ba b *

예제 출력 3

NONE

예제 입력 4

2
* zz
zz *

예제 출력 4

UNIQUE
z
z

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2022 F번

  • 문제를 만든 사람: Nils Gustafsson