#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 5010
int p[N];
int find(int x)
{
return p[x] != x ? p[x] = find(p[x]) : x;
}
int main()
{
int n, m, q;
int x, y, r1, r2;
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; i++) p[i] = i;
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &x, &y);
r1 = find(x); r2 = find(y);
if (r1 != r2) p[r2] = r1;
}
for (int i = 1; i <= q; i++)
{
scanf("%d%d", &x, &y);
r1 = find(x); r2 = find(y);
if (r1 == r2) printf("Yes\n");
else printf("No\n");
}
return 0;
}
题目链接: https://vijos.org/problems/P1034
并查集入门题