This page is still under construction.

Parts of this page are still being built. What you see may change.

Calvinball Championship Team Assignment

Time limit1sMemory limit256 MB

Summary
Assign n players to the fewest teams so no rival pair shares a team, breaking ties by lexicographically smallest team numbers.
Level

Medium6 of 10

Topics
Backtracking, Graph, Brute force
Solved
No attempts yet

Problem

The Calvinball championship is held again this year. A game is played by nn players with distinct names, and the players are divided into non-empty teams. There is no limit on the number of teams. Some pairs of players dislike each other. Disliking is symmetric: if player aa dislikes player bb, then bb also dislikes aa.

The organizing committee changed the rule for forming teams. Two players who dislike each other cannot be on the same team, and subject to that, the number of teams has to be as small as possible.

For example, suppose Calvin, Hobbes, Susie, Tom, Jerry, and Batman play, Batman dislikes the other five, and Tom dislikes Jerry and Hobbes. Three teams are enough: Batman alone, Tom with Susie, and Calvin with Hobbes and Jerry. Two teams are not enough, because Batman, Tom, and Jerry dislike each other and the three of them go to three different teams. Four teams is not an answer either, because a smaller number works.

Given the pairs of players who dislike each other, divide the players into teams under this rule.

Input

The first line contains the number of players nn and the number of pairs of players who dislike each other mm, separated by a space. (0≤n≤120 \le n \le 12, 0≤m≤n(n−1)/20 \le m \le n(n-1)/2) The players are numbered from 11 to nn.

Each of the next mm lines contains two distinct integers aia_i and bib_i. (1≤ai,bi≤n1 \le a_i, b_i \le n) This means that player aia_i and player bib_i dislike each other. The same pair is never given twice.

Output

Print the number of teams tt on the first line. On each of the next tt lines, print the numbers of the players on that team in increasing order, separated by spaces.

Several divisions can use the minimum number of teams, so exactly one of them is chosen by the following rule. Let tit_i be the number of the team that player ii belongs to, where teams are numbered from 11 in order of first appearance. That is, t1=1t_1 = 1, and ti≤1+max⁡(t1,…,ti−1)t_i \le 1 + \max(t_1, \dots, t_{i-1}) for every ii. Among the divisions that use the minimum number of teams, print the one whose sequence (t1,t2,…,tn)(t_1, t_2, \dots, t_n) is lexicographically smallest. Print the teams in order, from team 11 to team tt.

If n=0n = 0, print only 00 on the first line.

Examples5

  1. Example 1

    Input
    6 7
    1 6
    2 6
    3 6
    4 6
    5 6
    5 4
    2 4
    
    Expected output
    3
    1 2 3 5
    4
    6
    
  2. Example 2

    Input
    1 0
    
    Expected output
    1
    1
    
  3. Example 3

    Input
    5 0
    
    Expected output
    1
    1 2 3 4 5
    
  4. Example 4

    Input
    2 1
    1 2
    
    Expected output
    2
    1
    2
    
  5. Example 5

    Input
    5 10
    1 2
    1 3
    1 4
    1 5
    2 3
    2 4
    2 5
    3 4
    3 5
    4 5
    
    Expected output
    5
    1
    2
    3
    4
    5