Hide

Problem B
Translators' Dinner

It is time again for the annual International Convention for Phonetic Communication. Because there are attendees from all over the world, and they do not all speak the same languages, the organizers have hired translators to help out.

To thank the translators at the end of the conference for their hard work, the organizers want to arrange a dinner at a nice local restaurant. However, the restaurant only has small, two person tables, hence the translators will have to be divided into pairs. As the organizers would like the translators to have a nice evening, they prefer that two translators sitting at the same table are both able to speak the same language. Write a program to help the organizers determine a way to match up the translators in pairs, so that each of the translators speaks a language that the other also speaks.

Input

The first line contains two numbers $N$ and $M$, the number of languages spoken at the convention, and the number of hired translators respectively ($2 \leq N \leq 100$, $1 \leq M \leq 200$).

The following $M$ lines each describe a translator. Each of these lines contains two integers specifying the two languages that the translator speaks. Languages are identified by integers in the range $[0,N-1]$.

Translators are identified by integers in the range $[0,M-1]$. Translators are listed in order of increasing identifier (i.e. the first listed translator has identifier $0$).

There are no two translators who both speak the same two languages. Translators have been chosen such that any two languages spoken at the conference can be translated into one another, although it may take several translators.

Output

If it is possible to match up all translators such that each pair speaks a common language, output a possible matching: print $M/2$ lines, each line containing the two identifiers of a pair of matched translators. The pairs, as well as the translators within a pair, may be listed in any order.

There may be multiple possible matchings. In that case, print any one of them.

If it is not possible to match up all translators, output a single line containing the word “impossible”.

Sample Input 1 Sample Output 1
5 6
0 1
0 2
1 3
2 3
1 2
4 3
5 3
1 0
2 4
Sample Input 2 Sample Output 2
3 3
0 1
1 2
2 0
impossible

Please log in to submit a solution to this problem

Log in