Mikemao666 @ 2020-08-04 09:08:55
要了测试数据,发现是对的哇
#include <bits/stdc++.h>
using namespace std;
const int MAXI=1e4+1;
int f[MAXI];
int find(int x) {
if (x!=f[x])
f[x]=find(f[x]);
return f[x];
}
int n,m;
int main() {
scanf("%d%d",&n,&m);
for(int i=1; i<=n; ++i)f[i]=i;
while(m--) {
int c,a,b;
scanf("%d%d%d",&c,&a,&b);
if(c==1) {
f[find(a)]=find(b);
} else {
if(find(a)==find(b))puts("Y\n");
else puts("N\n");
}
}
return 0;
}
by Eon_Sky @ 2020-08-04 09:13:54
你都用puts还要啥\n啊
by Eon_Sky @ 2020-08-04 09:14:34
@Mikemao666 puts输出之后会自动换行大哥,把\n去了就能AC
by 傅天宇 @ 2020-08-04 09:48:55
同楼上
by Mikemao666 @ 2020-08-04 10:09:59
谢谢!