Riddle
Time limit3sMemory limit1024 MB
Decide whether one town can be picked from each given group so that every edge of the graph has a chosen endpoint.
Problem
The evil sorcerer Voldebyte has imprisoned the brave knight Bytter the Bold in his tower. As is his custom, Voldebyte promises to free Bytter once he solves one of his (still unsolved) riddles. Because Bytter managed to kill Voldebyte's pet dragon and nearly killed Voldebyte himself, Voldebyte has chosen an especially hard riddle. Here is the riddle he poses to Bytter:
Byteland is divided into counties, containing towns in total. In addition, some pairs of towns are connected by bidirectional roads. I want to choose one town in each county to be its capital so that, for every road, at least one of its two endpoints is a capital. Is this possible?
Help poor Bytter and solve the riddle for him.
Input
The first line contains three integers: (), the number of towns; (), the number of roads; and (), the number of counties. The towns are numbered from to .
Each of the next lines contains two integers and (, ), meaning there is a road between towns and . No pair of towns is connected by more than one road.
Each of the next lines describes one county. The -th of these lines starts with an integer (), the number of towns in county , followed by distinct integers, the numbers of the towns in county . The sum of all equals .
Output
Print a single line. If it is possible to choose the capitals so that every road has at least one capital endpoint, print TAK (which means yes in Polish). Otherwise print NIE (which means no in Polish).