本来想着10分钟过一道题的,没想到第一题直接全给我爆RE ???????
这代码哪里有问题了,本地可以过,洛谷IDE也可以过,一提交就全RE
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 100005;
const int inf = numeric_limits<int>::max();
int fa[MAXN];
int n, m;
int find(int x) {
if (fa[x] == x)
return x;
return fa[x] = find(fa[x]);
}
int unity(int x, int y) {
x = find(x), y = find(y);
if (x != y) fa[x] = y;
}
void init() {
for (int i = 1; i <= n; ++i) {
fa[i] = i;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
init();
for (int i = 0; i < m; ++i) {
int z, x, y;
cin >> z >> x >> y;
if (z == 1) {
unity(x, y);
} else {
cout << ((find(x) == find(y)) ? "Y" : "N") << endl;
}
}
}