#P6965. [NEERC 2016] Binary Code

    ID: 6123 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>2016Special Judge图论建模2-SAT字典树,TrieICPC

[NEERC 2016] Binary Code

题目描述

Ben has recently learned about binary prefix codes. A binary code is a set of nn distinct nonempty code words sis_{i} , each consisting of 0s and 1s.1s. A code is called a prefix code if for every iji ≠ j neither sis_{i} is a prefix of sjs_{j} nor sjs_{j} is a prefix of sis_{i} . A word xx is called a prefix of a word ww if there exists a possibly empty word yy , such that xy =w= w . For example, x=11x = 11 is a prefix of w=110w = 110 and x=0100x = 0100 is a prefix of w=0100w = 0100 .

Ben found a paper with nn lines of binary code in it. However, this paper is pretty old and there are some unreadable characters. Fortunately, each word contains at most one unreadable character.

Ben wants to know whether these nn lines could represent a binary prefix code. In other words, can he replace every unreadable character with 00 or 11 , so that the code becomes a prefix code?

输入格式

The first line contains integer nn -- the number of code words (1n5105).(1 \le n \le 5 · 10^{5}).

Next nn lines contain nonempty code word records, one per line. Each code word record consists of 0, 1 and ? characters. Every code word record contains at most one ? character that represents unreadable character.

The total length of words does not exceed 51055 · 10^{5} .

输出格式

Output NO in the first line if the code cannot be a prefix code.

Otherwise, output YES in the first line. Next nn lines shall contain code words in the same order as the corresponding code word records in the input.

If there are several prefix codes, that could have been written on the paper, output any one.

4
00?
0?00
?1
1?0

YES
000
0100
11
100

3
0100
01?0
01?0

NO

提示

Time limit: 2 s, Memory limit: 2048 MB.