#P9074. Circle Arrangement Avoiding Club Repetition

    ID: 22233 Type: Default 1000ms 256MiB

Circle Arrangement Avoiding Club Repetition

Circle Arrangement Avoiding Club Repetition

There are n students, labeled from 1 to n, and they have joined m clubs. Due to a strange reason, any two clubs share at most one common member. The school wants to organize a contest by arranging the n students in a circle. To prevent cheating, the principal requires that any three consecutive students on the circle should not all belong to the same club.

You are given the membership information for the clubs. Your task is to find one circular arrangement of the students that satisfies the above condition, or determine that no such arrangement exists.

Note that a triple of students i, j, k violates the condition if there exists a club such that all three students are members of that club. In LaTeX, the condition for a triple (a, b, c) is:
\(\nexists\; C \text{ such that } a \in C \wedge b \in C \wedge c \in C\).

inputFormat

The input begins with two integers n and m (the number of students and clubs respectively).

Then follow m lines. Each line starts with an integer k indicating the number of members in that club, followed by k distinct integers representing the student IDs who are members of that club.

All integers are separated by spaces.

outputFormat

If a valid circular arrangement exists, print a single line containing n integers — a permutation of 1 through n — which represents the order of students in the circle. The circle is considered cyclic, so the triple formed by the last two students and the first student also must satisfy the condition.

If no valid arrangement exists, output a single line containing the word Impossible.

sample

3 1
3 1 2 3
Impossible

</p>