Lisbeth_Rivaille @ 2018-08-28 18:27:47
#include <iostream>
#include <cstdio>
using namespace std;
int n,m,fa[1001000],x,y,z;
int find(int now){
if(fa[now]==now)return now;
return fa[now]=find(fa[now]);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)fa[i]=i;
for(int i=1;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
if(x==1)fa[fa[y]]=z;
else if(find(z)==find(y))printf("Y\n");
else printf("N\n");
}
return 0;
}
1,4,5AC,其他RE,看不出是为虾米,求助qwq
by LCuter @ 2018-08-28 18:37:50
数组小点,才1w
by Reywmp @ 2018-08-28 18:40:11
@常暗踏阴 开100w也不会爆吧
by LCuter @ 2018-08-28 18:41:21
@ALIENWARE 嗯,但是我还是觉得尽量别太浪费
by Lisbeth_Rivaille @ 2018-08-28 18:41:59
@常暗踏阴 10000开过,依然炸qwq
by LCuter @ 2018-08-28 18:42:32
我的
#include<bits/stdc++.h>
using namespace std;
int n,m,prt[10010];
int getfather(int k){
if(prt[k]==k){
return k;
}
return prt[k]=getfather(prt[k]);
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;++i){
prt[i]=i;
}
for(int i=1;i<=m;++i){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a==1){
prt[getfather(b)]=getfather(c);
}
else{
if(getfather(b)==getfather(c)){
printf("Y\n");
}
else{
printf("N\n");
}
}
}
return 0;
}
by LCuter @ 2018-08-28 18:42:54
@待捕捉蒟蒻QvvQ 您真的是wx?
by Lisbeth_Rivaille @ 2018-08-28 18:43:34
@常暗踏阴 是啊,我有空用大号给你私信证实一下qwq%%%
by Lisbeth_Rivaille @ 2018-08-28 18:46:19
@常暗踏阴 https://www.luogu.org/recordnew/show/10267689 ,看去吧,我真的布吉岛肿么肥四qwq
by Lolierl @ 2018-08-28 18:48:27
@待捕捉蒟蒻QvvQ
修改不用路径压缩?
by Lisbeth_Rivaille @ 2018-08-28 18:49:22
@Lolierl 压了啊qwq