Mán lì

Time limit: 0.6s Memory limit: 256MB Input: Output:

There are NN participants at 插入编程竞赛 which need to be accommodated in a hotel with NN available rooms.

Among these participants there are exactly MM friendships. If two participants are friends, then they can be assigned to the same room. Otherwise, they must be assigned to different rooms.

Task

Find the lexicographically minimum assignment of the NN participants to the NN available rooms of the hotel. We can show that such an assignment always exists.

An assignment A1,A2,,ANA_1,A_2,\ldots,A_N is lexicographically smaller than another assignment B1,B2,,BNB_1,B_2,\ldots, B_N if there exists a position 1iN1 \le i \le N for which:

  • Aj=BjA_j=B_j, for all 1j<i1 \le j<i.
  • Ai<BiA_i<B_i.

Here, AiA_i denotes the number of the room assigned to the ii-th participant in the first assignment. Similarly, BiB_i denotes the number of the room assigned to the ii-th participant in the second assignment.

Input data

The first line of input containts integers NN and MM - the number of participants, and the number of friendships, respectively.

Each of the next MM lines of input contains two integers UiU_i and ViV_i (1Ui,ViN1 \le U_i, V_i \le N, UiViU_i \neq V_i), meaning that participants UiU_i and ViV_i are friends. Note that this relationship is bidirectional.

Output data

Print the lexicographically minimum assignment A1,A2,,ANA_1,A_2,\ldots,A_N (1AiN1 \le A_i \le N for all ii). We can show that such an assignment always exists.

Constraints and clarifications

  • 1N300 0001 \leq N \leq 300 \ 000
  • 0Mmin(n(n1)2,300 000)0 \leq M \leq \min \left(\frac{n(n-1)}{2}, 300 \ 000 \right)
  • 1Ui,ViN1 \leq U_i, V_i \leq N, UiViU_i \neq V_i for all 1iM1 \leq i \leq M
  • It is guaranteed that all friendships given in the input are pairwise distinct.
# Score Constraints
1 14 1N71 \leq N \leq 7
2 19 1N3 0001 \leq N \leq 3 \ 000
3 31 1M3 0001 \leq M \leq 3 \ 000
4 36 No additional restrictions

Example 1

stdin

6 4
1 4
1 5
3 5
6 2

stdout

1 2 3 1 3 2

Explanation

Participant 11 is assigned to room 11.

Participant 22 is assigned to room 22.

Participant 33 is assigned to room 33.

Participant 44 is assigned to room 11.

Participant 55 is assigned to room 33.

Participant 66 is assigned to room 22.

For example, since participants 11 and 44 are friends, they can be assigned to the same room.

We can show that, under the given constratints, this is the lexicographically minimum assignment.

Example 2

stdin

4 6
1 2
1 3
1 4
2 3
2 4
3 4

stdout

1 1 1 1

Explanation

Here, all of the participants are friends with each other. Therefore, they can all be assigned to room 11.

Log in or sign up to be able to send submissions!