#P1551. 亲戚

亲戚

Description

Rules: If xx and yy are relatives, and yy and zz are relatives, then xx and zz are also relatives. If xx and yy are relatives, then all relatives of xx are also relatives of yy, and all relatives of yy are also relatives of xx.

Input Format

The first line contains three integers n,m,pn,m,p (n,m,p5000n,m,p \le 5000), representing that there are nn people, mm kinship relations, and pp queries.

Each of the following mm lines contains two integers Mi,MjM_i,M_j (1Mi, Mjn1 \le M_i,~M_j \le n), indicating that MiM_i and MjM_j are relatives.

Then the next pp lines each contain two integers Pi,PjP_i,P_j, asking whether PiP_i and PjP_j are relatives.

Output Format

Output pp lines. Each line contains either Yes or No, indicating whether the answer to the ii-th query is “are relatives” or “are not relatives.”

6 5 3
1 2
1 5
3 4
5 2
1 3
1 4
2 3
5 6
Yes
Yes
No

Hint

Translated by ChatGPT 5