0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:52:02 +00:00

P3367 【模板】并查集

R41046097
This commit is contained in:
Baoshuo Ren 2020-11-01 21:54:10 +08:00 committed by Baoshuo Ren
parent 8136c6e776
commit 6069f24be1
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

27
problem/P3367/P3367.cpp Normal file
View File

@ -0,0 +1,27 @@
#include<bits/stdc++.h>
using namespace std;
int f[1000005];
int find(int x) {
return f[x] == x ? x : f[x] = find(f[x]);
}
int main() {
int n, m, z, x, y;
cin >> n >> m;
for(int i = 0; i < n ; i++) {
f[i] = i;
}
while(m--) {
cin >> z >> x >> y;
if(z == 1) {
f[find(x)] = find(y);
}
else {
cout << (find(x) == find(y) ? "Y" : "N") << endl;
}
}
return 0;
}