sky_silence_gdk @ 2017-11-01 13:18:32
using namespace std;
class bcj
{ public:
int a[10001];
int find_set(int x)
{
if(a[x]!=x)
a[x]=find_set(a[x]);
else
return x;
}
void merge(int x,int y)
{
x=find_set(x),y=find_set(y);
if(x==y)
return ;
else
a[x]=y;
}
int make_set(int n)
{
for(int i=1;i<=n;i++)
a[i]=i;
}
};
int main()
{
int n,m;
scanf("%d %d",&n,&m);
bcj q;
q.make_set(n);
for(int i=1;i<=m;i++)
{
int t,x,y;
scanf("%d %d %d",&t,&x,&y);
if(t==1)
q.merge(x,y);
else
{
if(q.find_set(x)==q.find_set(y))
printf("Y\n");
else
printf("N\n");
}
}
}
by Gae_Blog @ 2017-11-06 23:29:04
@sky_silence_gdk 这种re一般是find函数递归爆栈导致的,可能是评测机骨骼比较清奇?