This page is still under construction.

Parts of this page are still being built. What you see may change.

Experiment

Time limit2sMemory limit1024 MB

Summary
Given users with group memberships and pairs of opposed users, decide whether a set of users can be chosen with at most one per group and at least one user from each opposed pair.
Level

Hard8 of 10

Topics
Graph, Simulation, Greedy, Implementation
Solved
No attempts yet

Problem

Junwon works as a data scientist at Sunlin Internet Corporation. He wants to select beta testers for the company's new service.

There are NN users who are candidates for beta testers. Based on their past service usage records, the NN users are divided into MM user groups in total, and each user belongs to between 00 and MM user groups. (M=0M = 0 is possible. In this case, think of it as having no groups at all.)

When Junwon selects some of these NN users as beta testers, the following conditions must be satisfied.

  • Condition 1: At most one beta tester can be selected from each user group.
  • Condition 2: For any two users with opposing tendencies, at least one of them must be selected as a beta tester.
    • The pairs of users with opposing tendencies are given in the input.

Help Junwon select the beta testers.

Input

The first line of the input gives four integers NN, MM, AA, BB.

The next AA lines each give two integers ii, jj. This means user ii belongs to group jj, and satisfies 1≤i≤N1 \le i \le N, 1≤j≤M1 \le j \le M.

The next BB lines each give two integers ii, jj. This means user ii and user jj have opposing tendencies, and satisfies 1≤i,j≤N1 \le i, j \le N, i≠ji \neq j.

Output

If Junwon can select the beta testers so that the conditions are satisfied, print "TAK"; otherwise, print "NIE".

Constraints

  • 1≤N≤1051 \le N \le 10^5
  • 1≤M≤1051 \le M \le 10^5
  • 0≤A≤5×1050 \le A \le 5 \times 10^5
  • 0≤B≤2×1050 \le B \le 2 \times 10^5

Examples2

  1. Example 1

    Input
    2 3 0 0
    
    Expected output
    TAK
    
  2. Example 2

    Input
    5 1 5 10
    1 1
    2 1
    3 1
    4 1
    5 1
    2 1
    3 1
    2 3
    1 4
    4 2
    4 3
    1 5
    2 5
    3 5
    5 4
    
    Expected output
    NIE