请问这样子写为什么不能AC
查看原帖
请问这样子写为什么不能AC
680000
Xealth楼主2024/4/11 17:31
#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;
}

2024/4/11 17:31
加载中...