program experiment;

const
	maxn = 100;

var
	i, j, k, l, n: longint;
	best, last, chg, next: longint;
	can: boolean;
	u: array [1..maxn, 1..maxn] of boolean;
	b, r: array [1..maxn] of longint;
	z, za: array [1..maxn] of longint;
	w: array [1..maxn] of boolean;

begin
	reset(input, 'exp.in');
	rewrite(output, 'exp.out');

	readln(n);
	assert((1 <= n) and (n <= maxn));
	for i := 1 to n do begin
		read(b[i]);
		assert(b[i] in [0, 1]);
		read(r[i]);
		assert((0 <= r[i]) and (r[i] <= n - 1));
		for j := 1 to r[i] do begin
			read(k);
			assert((1 <= k) and (k < i));
			assert(not u[i][k]);
			u[i][k] := true;
		end;
	end;

	best := n + 1;
	for i := 0 to 1 do begin
		last := i;

		chg := 0;

		fillchar(w, sizeof(w), 0);

		for j := 1 to n do begin
			next := 0;
			for k := 1 to n do if not w[k] and (b[k] = last) then begin
				can := true;
				for l := 1 to n do begin
					if u[k][l] and not w[l] then 
						can := false;
				end;
				if can then begin
					next := k;
					break;
				end;
			end;
			if next = 0 then begin
    			for k := 1 to n do if not w[k] and (b[k] <> last) then begin
    				can := true;
    				for l := 1 to n do begin
    					if u[k][l] and not w[l] then 
    						can := false;
    				end;
    				if can then begin
    					next := k;
    					break;
    				end;
    			end;
			end;
			z[j] := next;
			if b[next] <> last then
				inc(chg);
			w[next] := true;
			last := b[next];
		end;

		if chg < best then begin
			best := chg;
			za := z;
		end;
	end;

	writeln(best);
	for i := 1 to n do begin
		write(za[i]);
		if i < n then
			write(' ');
	end;
	writeln;

	close(input);
	close(output);
end.