This page is still under construction.

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

Calvinball team split

Time limit1sMemory limit256 MB

Summary
Split up to 16 players into the fewest teams with no disliked pair sharing a team, breaking ties by the smallest assignment sequence.
Level

Medium7 of 10

Topics
Graph, Backtracking, Bit manipulation, Dynamic programming
Solved
No attempts yet

Problem

The Calvinball championship is held again this year. A game of Calvinball is played by nn players with distinct names, split into some number of non-empty teams. Some players dislike each other. Disliking is symmetric: if player aa dislikes player bb, then bb dislikes aa.

The International Calvinball Disorganization changed the team selection rule right before the tournament. No two players who dislike each other may share a team, and under that condition the number of teams must be as small as possible.

For example, suppose Calvin (1), Hobbes (2), Susie (3), Tom (4), Jerry (5) and Batman (6) play, Batman dislikes the other five, and Tom dislikes Jerry and Hobbes. Batman, Tom and Jerry all dislike one another, so the three of them need different teams and two teams are impossible. Three teams work: Calvin, Hobbes, Susie and Jerry on one team, Tom alone, Batman alone. Four teams is not the answer, because a smaller number of teams is possible.

Given which players dislike each other, write a program that finds a split with the smallest number of teams. When several such splits exist, print the one selected by the output rule below.

Input

The first line contains the number of players nn and the number of pairs of players who dislike each other mm. (0≤n≤160 \le n \le 16, 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 the numbers aia_i and bib_i of two players who dislike each other. (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i) No pair is given twice. Two lines that differ only in order count as the same pair.

Output

On the first line print the minimum number of teams tt. On each of the next tt lines print the numbers of the players on one team, separated by single spaces.

Print the numbers inside each team in increasing order, and print the teams in increasing order of their smallest player number. When several splits reach the minimum number of teams, choose one by this rule. Number the teams from 11 to tt in the order they are printed, and let cic_i be the number of the team that player ii belongs to. Print the split whose sequence c1,c2,…,cnc_1, c_2, \dots, c_n is lexicographically smallest.

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

Examples2

  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
    5 0
    
    Expected output
    1
    1 2 3 4 5