Skip to content

Commit 4b1ad02

Browse files
committed
add question
1 parent 95e33ca commit 4b1ad02

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

problem_0/question.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Polycarp has $n$ different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100".
2+
3+
Polycarp wants to offer his set of $n$ binary words to play a game "words". In this game, players name words and each next word (starting from the second) must start with the last character of the previous word. The first word can be any. For example, these sequence of words can be named during the game: "0101", "1", "10", "00", "00001".
4+
5+
Word reversal is the operation of reversing the order of the characters. For example, the word "0111" after the reversal becomes "1110", the word "11010" after the reversal becomes "01011".
6+
7+
Probably, Polycarp has such a set of words that there is no way to put them in the order correspondent to the game rules. In this situation, he wants to reverse some words from his set so that: the final set of $n$ words still contains different words (i.e. all words are unique); there is a way to put all words of the final set of words in the order so that the final sequence of $n$ words is consistent with the game rules.
8+
9+
Polycarp wants to reverse minimal number of words. Please, help him.
10+
11+
12+
-----Input-----
13+
14+
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
15+
16+
The first line of a test case contains one integer $n$ ($1 \le n \le 2\cdot10^5$) — the number of words in the Polycarp's set. Next $n$ lines contain these words. All of $n$ words aren't empty and contains only characters '0' and '1'. The sum of word lengths doesn't exceed $4\cdot10^6$. All words are different.
17+
18+
Guaranteed, that the sum of $n$ for all test cases in the input doesn't exceed $2\cdot10^5$. Also, guaranteed that the sum of word lengths for all test cases in the input doesn't exceed $4\cdot10^6$.
19+
20+
21+
-----Output-----
22+
23+
Print answer for all of $t$ test cases in the order they appear.
24+
25+
If there is no answer for the test case, print -1. Otherwise, the first line of the output should contain $k$ ($0 \le k \le n$) — the minimal number of words in the set which should be reversed. The second line of the output should contain $k$ distinct integers — the indexes of the words in the set which should be reversed. Words are numerated from $1$ to $n$ in the order they appear. If $k=0$ you can skip this line (or you can print an empty line). If there are many answers you can print any of them.
26+
27+
28+
-----Example-----
29+
Input
30+
4
31+
4
32+
0001
33+
1000
34+
0011
35+
0111
36+
3
37+
010
38+
101
39+
0
40+
2
41+
00000
42+
00001
43+
4
44+
01
45+
001
46+
0001
47+
00001
48+
49+
Output
50+
1
51+
3
52+
-1
53+
0
54+
55+
2
56+
1 2

0 commit comments

Comments
 (0)