我 没 在 做 梦 吧?
  • 板块灌水区
  • 楼主_LFC_
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/24 21:18
  • 上次更新2024/8/24 21:21:52
查看原帖
我 没 在 做 梦 吧?
1431280
_LFC_楼主2024/8/24 21:18

不是,,, 10410^4 的数组爆了 125MB125MB 的内存?

太无聊切下水题结果你给我来个这个 ?

#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;

int fa[N];

inline int find (int x) {
	return x == fa[x] ? x : fa[x] = find (fa[x]);
}

int main() {
	int n, m;
	scanf ("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++) {
		fa[i] = i;
	}
	int opt, x, y;
	for (int i = 1; i <= m; i ++) {
		scanf ("%d%d%d", &opt, &x, &y);
		if (opt == 1) {
			fa[find(x)] = fa[y];
		} else {
			if (find(x) == find(y)) printf ("Y\n");
			else printf ("N\n");
		}
	}
	return 0;
}
2024/8/24 21:18
加载中...