time limit per test: 0.25 sec. memory limit per test: 65536 KB
input: standard output: standard
Vasya likes to play quests very much. He likes to click here and there and he enjoys jokes which quests are full of. But there are also a lot of different puzzles in quests and Vasya has very hard time solving these puzzles. So once he encountered a puzzle he is unable to solve in spite of all efforts made. But fortunately Vasya is a great programmer and he was able to write a program that helped him to solve the puzzle and complete the quest. The Vasya's puzzle is a matrix with each of its cells having either black or white color. The click on the cell changes its color and the color of neighboring cells to the opposite one. The goal is to make all the cells to be colored in the same color. Your task will be a little bit more complicated. Suppose there are N cells numbered from 1 to N. Each cell has a predefined set of cells associated with it. When person clicks on a cell the color of the cells associated with it changes. You will be given a description of all cells groups and initial cells coloring. You should output the sequence of cells which should be clicked to obtain a single color for all the cells. If there are a number of different solutions, you can choose any one.
Input
The first line contains a single integer number N (1 <= N <= 200). The i+1-th line (1 <= i <= N) contains the description of the set of cells associated with i-th cell. Each description starts with the integer number k - number of cells in the set, k distinct integer numbers (numbers of cells) follow. The last line contains N zeroes and ones - initial cells coloring.
Output
If it is impossible to make all cells to be colored the same color, you should output a single number -1. Otherwise you should output integer number L - the number of clicks required to solve the puzzle and then L numbers - cells which are to be clicked.