mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-10 07:38:49 +00:00
P1551 亲戚
R43109248
This commit is contained in:
parent
87f9e1d85d
commit
0962fb88c1
31
problem/P1551/P1551.cpp
Normal file
31
problem/P1551/P1551.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, m, p, x, y, j, f[5005];
|
||||
|
||||
int find(int x) {
|
||||
if (f[x] == x) return f[x];
|
||||
return f[x] = find(f[x]);
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> m >> p;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
f[i] = i;
|
||||
}
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> x >> y;
|
||||
f[find(x)] = find(y);
|
||||
}
|
||||
for (int i = 1; i <= p; i++) {
|
||||
cin >> x >> y;
|
||||
if (find(x) == find(y)) {
|
||||
cout << "Yes" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "No" << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user