Basin City Surveillance
Time limit2sMemory limit256 MB
Decide whether k vertices can be chosen so no two are adjacent in a graph of degree at most four.
- Level
Medium7 of 10
- Topics
- Backtracking, Graph, Brute force
- Solved
- No attempts yet
Problem
BASIN CITY has a very high crime rate. The police are tightening security and want to install traffic drones at intersections to watch for cars running a red light. When a car runs a red light, the drone at that intersection chases the car, stops it, and gives the driver a ticket.
The drones are not smart. A drone breaks off a chase before it reaches the next intersection, because any farther out it would lose the way back to its home, the traffic light it is assigned to. A drone also cannot detect another drone, so the police R&D department concluded that once a drone sits at an intersection, no drone should be placed at an intersection joined to it by a road. As in many other cities, no intersection in BASIN CITY has more than four neighbouring intersections.
The government pays for the drones, so the police want to buy as many as they are allowed to. Given the number of drones , decide whether exactly drones can be placed so that no two of them sit at neighbouring intersections.
Input
The first line contains the number of drones to place, (). The second line contains the number of intersections in BASIN CITY, (). The next lines describe the intersections in order. The -th of those lines starts with an integer , the number of intersections neighbouring intersection (), followed by the indices of those neighbours. The indices are distinct and different from . The intersections are numbered from 1 to .
Output
Print possible on a single line if drones can be placed so that no two neighbouring intersections both hold a drone. Otherwise print impossible.