260. Puzzle
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+1th line (1 <= i <= N) contains the description of the set of cells associated with ith 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.
Sample test(s)
Input
9
3 1 2 4
4 1 2 3 5
3 2 3 6
4 1 4 5 7
5 2 4 5 6 8
4 3 5 6 9
3 4 7 8
4 5 7 8 9
3 6 8 9
1 0 1 0 1 0 1 0 1
Output
9
1 2 3 4 5 6 7 8 9
Author:  Igor A. Kulkin

Resource:  Saratov SU Contest: Golden Fall 2004

Date:  October 2, 2004

Server time: 20180222 09:57:27  Online Contester Team © 2002  2016. All rights reserved. 

