Calvinball team split
Time limit1sMemory limit256 MB
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 players with distinct names, split into some number of non-empty teams. Some players dislike each other. Disliking is symmetric: if player dislikes player , then dislikes .
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 and the number of pairs of players who dislike each other . (, ) The players are numbered from to .
Each of the next lines contains the numbers and of two players who dislike each other. (, ) 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 . On each of the next 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 to in the order they are printed, and let be the number of the team that player belongs to. Print the split whose sequence is lexicographically smallest.
If , print only on the first line.