Two Teams for the Picnic
Alice and Bob are organising a picnic for their n friends, numbered from 1 to n. The friends
will play games all afternoon, so Alice and Bob want to split everyone into two teams: Alice's team
(team 1) and Bob's team (team 2). Unfortunately, some friends are rivals, and two rivals placed on
the same team will spend the whole picnic arguing instead of playing.
You are given m rivalries. Each rivalry is a pair of different friends u and v, and it means
that u and v must be on different teams. Rivalries are symmetric, and the same pair may be
listed more than once. Friends who are not involved in any rivalry can go to either team.
Call a split valid if every friend is on exactly one of the two teams and no rivalry pair shares a team. A valid split is rarely unique, so Alice and Bob agree on a tie-breaking rule. Say that two friends are linked if one can get from one to the other through a chain of rivalries (every friend is linked to themselves). Within each group of mutually linked friends, the friend with the smallest number always joins Alice's team.
If a valid split exists, this rule determines it completely. Print it, or report that no valid split exists.
Input
The first line contains two integers n and m (1 ≤ n ≤ 2·10^5, 0 ≤ m ≤ 2·10^5): the number of
friends and the number of rivalries.
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v): a rivalry
between friends u and v.
Output
If no valid split exists, print the single word IMPOSSIBLE.
Otherwise print n integers t_1, t_2, ..., t_n separated by spaces, where t_i is 1 if friend
i joins Alice's team and 2 if they join Bob's team, following the rule above.
Notes
In the first example, friends 1, 2, 3, 4 are linked, and friend 1 goes to Alice's team.
Then 2 and 4 (rivals of 1) must go to Bob's team, and 3 (a rival of 2) to Alice's team.
Friends 5 and 6 form their own group, whose smallest member 5 goes to Alice's team. Friend 7
has no rivals and is alone in their group, so they join Alice's team.
In the second example, friends 1, 2 and 3 are pairwise rivals. Two of them must end up on the
same team, so the answer is IMPOSSIBLE.