luogu#P7965. [COCI 2021/2022 #2] Kutije
[COCI 2021/2022 #2] Kutije
Problem Description
Matrin has toys in boxes. The boxes are numbered . Initially, each box contains one toy whose number is the same as the box number.
Matrin invites friends to his home to play with the toys. He notices that after each friend finishes playing, they will put the toy that was originally in box into box .
You are given queries. For each query, you may invite friends in any order, and each friend may be invited any number of times. Determine whether there exists a plan such that toy ends up being placed into box .
Input Format
The first line contains three positive integers , representing the number of boxes / toys, the number of friends, and the number of queries.
The next lines each contain integers . The testdata guarantees that is a permutation of .
The next lines each contain two integers .
Output Format
Output lines. Each line should contain a string (yes) or (no).
4 1 3
1 2 4 3
1 1
1 2
3 4
DA
NE
DA
4 2 4
2 1 3 4
1 2 4 3
2 1
3 4
1 4
2 3
DA
DA
NE
NE
6 2 2
2 1 4 5 3 6
3 2 4 1 5 6
1 5
6 3
DA
NE
Hint
[Sample 1 Explanation]
- Query : Initially, toy is already in box , so output .
- Query : For the second query, there is no plan that satisfies the requirement, so output .
- Query : It is enough to invite friend , so output .
[Constraints and Notes]
This problem uses bundled subtasks.
- Subtask 1 (15 pts): .
- Subtask 2 (10 pts): . For each query, if the answer is , it is guaranteed that there exists a plan that invites at most friends.
- Subtask 3 (10 pts): .
- Subtask 4 (35 pts): No special restrictions.
For of the testdata, , , and .
[Hints and Explanation]
This problem is translated from COCI 2021-2022 CONTEST #2 Task 2 Kutije.
The score of this problem follows the original COCI setting, with a full score of .
Translated by ChatGPT 5