luogu#P7965. [COCI 2021/2022 #2] Kutije

    ID: 7310 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>并查集2021广度优先搜索 BFSCOCI(克罗地亚)

[COCI 2021/2022 #2] Kutije

Problem Description

Matrin has toys in nn boxes. The boxes are numbered 1,2,3,,n1,2,3,\cdots,n. Initially, each box contains one toy whose number is the same as the box number.

Matrin invites mm 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 ii into box pip_i.

You are given qq 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 aa ends up being placed into box bb.

Input Format

The first line contains three positive integers n,m,qn,m,q, representing the number of boxes / toys, the number of friends, and the number of queries.

The next mm lines each contain nn integers pip_i. The testdata guarantees that pip_i is a permutation of 1n1 \sim n.

The next qq lines each contain two integers a,ba,b.

Output Format

Output qq lines. Each line should contain a string DA\texttt{DA} (yes) or NE\texttt{NE} (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 11: Initially, toy 11 is already in box 11, so output DA\texttt{DA}.
  • Query 22: For the second query, there is no plan that satisfies the requirement, so output NE\texttt{NE}.
  • Query 33: It is enough to invite friend 11, so output DA\texttt{DA}.

[Constraints and Notes]

This problem uses bundled subtasks.

  • Subtask 1 (15 pts): m=1m=1.
  • Subtask 2 (10 pts): 1n,m,q1001 \le n,m,q \le 100. For each query, if the answer is DA\texttt{DA}, it is guaranteed that there exists a plan that invites at most 22 friends.
  • Subtask 3 (10 pts): 1n,m,q1001 \le n,m,q \le 100.
  • Subtask 4 (35 pts): No special restrictions.

For 100%100\% of the testdata, 1n,m10001 \le n,m \le 1000, 1q5×1051 \le q \le 5 \times 10^5, and 1a,bn1 \le a,b \le n.

[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 7070.

Translated by ChatGPT 5