P6126 [JSOI2012] Archaeopteryx.
Description
Recently, an “Archaeopteryx Specialty Store” appeared in the Jinxian River area, but this is not just a sudden whim.
As early as ancient times, the Jinxian River area attracted flocks of Archaeopteryx with its beautiful environment and suitable temperature. Archaeopteryx are a united kind of bird. They always use various ways to strengthen communication within the group, and gatherings are one of them. Because gatherings can not only strengthen friendships between friends, but also help them meet new friends.
Now there are $N$ Archaeopteryx, numbered from $1$. For the $i$-th Archaeopteryx, it has $M_i$ friends it knows, whose indices are $F_{i,1},F_{i,2},\dots,F_{i,M_i}$. The “knowing” relationship is one-way, which means if the $s$-th Archaeopteryx knows the $t$-th Archaeopteryx, then the $t$-th Archaeopteryx does not necessarily know the $s$-th Archaeopteryx.
There are two gathering places: one upstream and one downstream. For each gathering place, it must satisfy that for every Archaeopteryx in that place, it has exactly an even number of friends it knows who are also in the same place. Of course, every Archaeopteryx must be in exactly one of the two gathering places.
Now you need to provide an arrangement. You only need to output the indices of the Archaeopteryx that are upstream. If there are multiple solutions, output any one of them.
Input Format
The input contains $N+1$ lines. The first line is the integer $N$, representing the number of Archaeopteryx.
In the next $N$ lines, on line $i+1$, the first integer is $M_i$, representing the number of friends of the $i$-th bird. Then there are $M_i$ integers $F_{i,1},F_{i,2},\dots,F_{i,M_i}$, representing the indices of the friends of the $i$-th Archaeopteryx.
Output Format
The output contains $2$ lines. The first line has a non-negative integer $k$, representing the number of Archaeopteryx attending the gathering upstream. The second line has $k$ positive integers, representing the indices of these $k$ Archaeopteryx. You may output them in any order. If the requirement cannot be satisfied, output only one line `Impossible`.
Explanation/Hint
#### Constraints
- For $100\%$ of the testdata, $1 \le N \le 2000$.
Translated by ChatGPT 5