#P6378. [PA 2010] Riddle

[PA 2010] Riddle

Description

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

Please choose some key vertices such that each part has exactly one key vertex, and each edge has at least one endpoint that 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 that there is an edge between aa and bb.

The next kk lines: the first integer is ww, meaning this part has ww vertices; then follow ww integers, which are the indices of the vertices in this part.

Output Format

If it is possible, output TAK; otherwise output NIE.

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

Hint

Constraints

For all testdata, it is guaranteed that 1k,wn1061 \le k, w \le n \le 10^6, w=n\sum w = n, 1a,bn1 \le a, b \le n, 0m1060 \le m \le 10^6.

Translated by ChatGPT 5