#graph504. Riddle

Riddle

Riddle

Problem Source

PA 2010

Problem Description

An undirected graph with nn vertices and mm edges is divided into kk parts. Each part contains some of the vertices.

Select some "key vertices" such that every part contains exactly one key vertex, and at least one endpoint of every edge is a key vertex.

Input Format

The first line contains three integers n,m,kn, m, k.

The next mm lines each contain two integers a,ba, b, indicating an edge between aa and bb.

The next kk lines each begin with an integer ww, the number of vertices in that part, followed by ww integers: the vertex indices belonging to that part.

For all test cases, 1≤k,w≤n≤1061 \le k, w \le n \le 10^6, ∑w=n\sum w = n, 1≤a,b≤n1 \le a, b \le n, and 0≤m≤1060 \le m \le 10^6.

Output Format

If such a selection is possible, output TAK; otherwise output NIE.

Sample Input

6 5 2
1 2
3 1
1 4
5 2
6 2
3 3 4 2
3 1 6 5

Sample Output

TAK