Xealth @ 2024-04-11 17:31:22
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int fa[N];
int n, m;
int find(int x) {
if (fa[x] = x)
return x;
return fa[x] = find(fa[x]);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i ++)
fa[i] = i;
while (m --) {
int z, x, y;
cin >> z >> x >> y;
if (z == 1) {
fa[find(x)] = find(y);
} else {
if (find(x) == find(y))
cout << "Y" << endl;
else
cout << "N" << endl;
}
}
return 0;
}
by 苏子谦123 @ 2024-04-11 17:35:15
int find(int x) {
if (fa[x] = x)
return x;
return fa[x] = find(fa[x]);
}
改为
int find(int x) {
if (fa[x] == x)
return x;
return fa[x] = find(fa[x]);
}
by Xealth @ 2024-04-11 17:43:27
@苏子谦123 原来是蠢问题 谢谢大佬
by strNeko @ 2024-04-16 20:54:50
第一眼还没看出来
by shistd @ 2024-04-18 19:43:54
??? =&== ='s problem