Alice is the teacher of a class of
- Alice knows that some pair of students are very good friends and they must not be assigned to the same group.
- Alice also wants to minimize the difference between the sizes of the two groups.
Let's write a program to help Alice to do the grouping, in which the program should:
- Report
-1
if it is not possible to do the grouping. - Report the group assigned to each student that fulfills the requirements.
Input Specification
- The first line contains two integers
and , where denotes the number of students, and denotes the number of known relationships between students. - Following are
lines, and each line contains two integers and , which means student and are very good friends and they must not be assigned to the same group. Each relationship will only be provided once.
Test cases
- In our test cases, we have
and . - In
of the test cases, . - In another
of the test cases, the number of possible ways to group students .
Output Specification
- If there is no way to do the grouping, output
-1
. - Otherwise, output a string containing
characters representing the group assigned to each of the students. If the th student is assigned to group , then the th character in the string is1
. Otherwise, the th character in the string is2
. - The string should represent the grouping with minimum difference between the sizes of the two groups. (That is, the difference between the number of 1's and the number of 2's in the output should be minimized.) If there is a tie, output the lexicographically smallest solution.
Sample Input 1
4 3
1 2
3 4
1 3
Output for Sample Input 1
1221
Sample Input 2
3 3
1 2
1 3
2 3
Output for Sample Input 2
-1
Sample Input 3
6 4
1 2
1 3
4 6
4 5
Output for Sample Input 3
122211
Explanation
In Sample 1, since
In Sample 2, there is no way to do the grouping. The reason is that
In Sample 3,
Comments
Bro alice is a meanace, what teacher makes groups where no one are friends.