Party
Time limit1sMemory limit256 MB
Find the smallest number of parties so each student pairs with a willing volunteer and no volunteer takes two students at one party.
- Level
Medium7 of 10
- Topics
- Graph, Binary search
- Solved
- No attempts yet
Problem
The department is holding a party. students have to attend with a partner, and volunteers are available to be partners.
Each volunteer states in advance which students they are willing to partner. A volunteer never partners a student outside that list.
At one party a volunteer partners at most one student, so a single party may leave some students without a partner. The same volunteers can be invited to several parties instead. A student only has to attend one of those parties with a partner.
Parties are expensive, so fewer is better. Find the smallest number of parties that lets every student attend one of them with a partner.
Input
The first line contains the number of test cases . ()
The first line of each test case contains two integers and separated by a single space. is the number of students who need a partner and is the number of volunteers. (, )
The next lines describe the volunteers, line describing volunteer . Each line starts with a positive integer giving how many students that volunteer is willing to partner, followed by the numbers of those students separated by spaces. Students are numbered from to , and the numbers on one line are distinct.
Output
Print one line for each test case. If no number of parties lets every student attend with a partner, print impossible. Otherwise print a single integer, the smallest number of parties needed.