Bubble Cup V9 F Pokermon League challenge
View as PDFWelcome to the world of Pokermon, yellow little mouse-like creatures, who absolutely love playing poker!
Yeah, right…
In the ensuing Pokermon League, there are  registered Pokermon trainers, and existing trainer teams. Since there is a lot of jealousy between trainers, there are 
 pairs of trainers who hate each other. Their hate is mutual, there are no identical pairs among these, and no trainer hates himself (the world of Pokermon is a joyful place!). Each trainer has a wish list of length 
 teams he'd like to join. All the teams are divided into two conferences.
Your task is to divide players into teams and the teams into two conferences, so that:
- each trainer belongs to exactly one team
 - no team is in both conferences
 - total hate between conferences is at least 
 - every trainer is in a team from his wish list
 
Total hate between conferences is calculated as the number of pairs of trainers from teams from different conferences who hate each other.
Input Specification
The first line of input contains  non-negative integers:
- total number of Pokermon trainers
- number of pairs of trainers who hate each other
Each Pokermon trainer is represented by a number between .
The next  lines contain 
 integers 
 and 
 indicating that Pokermon trainers 
 and 
 hate each other.
The next  lines are in the following format:
Starting with Pokermon trainer , for every trainer in consecutive order:
- first number 
- a size of Pokermon trainers wish list
 - in the next line are positive integers 
- the teams Pokermon trainer would like to be on.
 
Each trainer's wish list will not contain repeating teams.
Teams on the wish lists are numbered in such a way that the set of all teams that appear on at least  wish list is the set of consecutive positive integers 
.
Output Specification
Contains 2 lines:
- The first line contains 
numbers, specifying the team every trainer is in. First for trainer
, then
, etc.
 - The second line contains 
numbers where for every team, starting with team
, there is an integer specifying the conference (
or
) of that team.
 
Constraints
Sample Input
4 3
1 2
2 3
4 1
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 15
16
2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 18
16
2 3 4 5 6 7 8 9 10 11 12 13 14 15 18 19
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 19
Sample Output
1 2 2 3
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Explanation
Conference  contains only team 
, and conference 
 contains all other teams. Total hate between conferences is 
 which is greater than 
.
Pokermon trainer  belongs to team 
, trainers 
 and 
 to team 
 and trainer 
 to team 
. Other teams are empty but they have been assigned a conference.
Comments