Chess Tournament
Time limit3sMemory limit256 MB
Count the equal two-team splits in which every pair across the teams played at least once, and print the lexicographically smallest team containing player 1.
- Level
Medium7 of 10
- Topics
- Graph, Union-find, Dynamic programming
- Solved
- No attempts yet
Problem
A big chess tournament is being held in your town, so you go and watch. Two teams A and B, each with players, face each other, and every player of team A plays one game against every player of team B. The team with more wins takes the title. In a drawn game each player gets point.
You do not know which players are on which team, but you wrote down every game played during the tournament. The catch is that some players also played outside the schedule, for practice or for fun. Some of those games were against a teammate, some against an opponent they had already faced. Can you still tell who belongs to which team?
Count the team assignments that agree with your list, that is, the assignments in which every pair of players from opposite teams appears in the list at least once. The two teams have no names, so swapping A and B gives the same assignment.
Input
The first line has the number of test cases (). Each test case is given as follows.
- One line with two integers and , the number of players per team and the number of recorded games (, ).
- Then lines, each with two different integers and (), meaning that player and player played a game.
The same pair may appear more than once. The sum of over all test cases is at most . Players are numbered 1 through , and at least one assignment that agrees with the list always exists.
Output
For each test case print two lines.
- The first line has the number of assignments modulo . The printed value must be at least 0 and less than . The remainder can be 0 even though an assignment exists.
- The second line has the players of the team that contains player 1, in increasing order, separated by single spaces. When several assignments are possible, print the one whose increasing sequence is lexicographically smallest.