Технокубок 2017 - Финал (только для онсайт-финалистов)
D
Innokenty and a Football League
Codeforces
1900
原题
← CE →
翻译中…

Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.

翻译中…

Each club's full name consist of two words: the team's name and the hometown's name, for example, "DINAMO BYTECITY". Innokenty doesn't want to assign strange short names, so he wants to choose such short names for each club that:

翻译中…
  1. the short name is the same as three first letters of the team's name, for example, for the mentioned club it is "DIN",
  2. or, the first two letters of the short name should be the same as the first two letters of the team's name, while the third letter is the same as the first letter in the hometown's name. For the mentioned club it is "DIB".
翻译中…

Apart from this, there is a rule that if for some club $*x*$ the second option of short name is chosen, then there should be no club, for which the first option is chosen which is the same as the first option for the club $*x*$. For example, if the above mentioned club has short name "DIB", then no club for which the first option is chosen can have short name equal to "DIN". However, it is possible that some club have short name "DIN", where "DI" are the first two letters of the team's name, and "N" is the first letter of hometown's name. Of course, no two teams can have the same short name.

翻译中…

Help Innokenty to choose a short name for each of the teams. If this is impossible, report that. If there are multiple answer, any of them will suit Innokenty. If for some team the two options of short name are equal, then Innokenty will formally think that only one of these options is chosen.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 1000$) — the number of clubs in the league.

翻译中…

Each of the next $*n*$ lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least $3$ and at most $20$.

翻译中…

Output

翻译中…

It it is not possible to choose short names and satisfy all constraints, print a single line "NO".

翻译中…

Otherwise, in the first line print "YES". Then print $*n*$ lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.

翻译中…

If there are multiple answers, print any of them.

翻译中…

Note

翻译中…

In the first sample Innokenty can choose first option for both clubs.

翻译中…

In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.

翻译中…

In the third example Innokenty can choose the second options for the first two clubs, and the first option for the third club.

翻译中…

In the fourth example note that it is possible that the chosen short name for some club $*x*$ is the same as the first option of another club $*y*$ if the first options of $*x*$ and $*y*$ are different.

翻译中…

样例

Input #1
2
DINAMO BYTECITY
FOOTBALL MOSCOW
Output #1
YES
DIN
FOO
InputCopy OutputCopy
Input #2
2
DINAMO BYTECITY
DINAMO BITECITY
Output #2
NO
InputCopy OutputCopy
Input #3
3
PLAYFOOTBALL MOSCOW
PLAYVOLLEYBALL SPB
GOGO TECHNOCUP
Output #3
YES
PLM
PLS
GOG
InputCopy OutputCopy
Input #4
3
ABC DEF
ABC EFG
ABD OOO
Output #4
YES
ABD
ABE
ABO
InputCopy OutputCopy
题目信息
标签
2-SAT
图论
贪心
模拟
最短路
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。