Experiment
Time limit2sMemory limit1024 MB
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 users who are candidates for beta testers. Based on their past service usage records, the users are divided into user groups in total, and each user belongs to between and user groups. ( is possible. In this case, think of it as having no groups at all.)
When Junwon selects some of these 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 , , , .
The next lines each give two integers , . This means user belongs to group , and satisfies , .
The next lines each give two integers , . This means user and user have opposing tendencies, and satisfies , .
Output
If Junwon can select the beta testers so that the conditions are satisfied, print "TAK"; otherwise, print "NIE".