Paintball
Time limit1sMemory limit256 MB
Assign each of N players a visible neighbor as target so every player is hit exactly once, choosing the lexicographically smallest such assignment.
Problem
Marek and his classmates finished their university studies and celebrated with a game of paintball. After an hour something odd happened: every player had exactly one bullet left. Marek got curious and wanted to know whether every player can be hit exactly once, assuming nobody moves.
The situation at the moment when each player has one bullet is given as a list of pairs of players who can see each other. If a player can see another player, he can fire at him. Choose a target for every player so that every player is hit exactly once.
In other words, player picks one player he can see as his target, and every player is picked as a target exactly once.
Input
The first line contains two space separated integers and (, ), where is the number of players and is the number of pairs who can see each other. Players are numbered through .
Each of the next lines contains two space separated integers and (), meaning that players and can see each other. No pair is given more than once.
Output
If no assignment of targets hits every player exactly once, print Impossible on the first line.
Otherwise print lines. The -th line holds the number of the target of player . If several assignments work, print the one whose sequence (target of player , target of player , ..., target of player ) is lexicographically smallest.