题面:
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<unordered_map>
#define ll long long
#define llu unsigned ll
#define iu unsigned int
using namespace std;
const int maxn=100010;
int f[maxn];
int fi(int x)
{
if(f[x]!=x)
f[x]=fi(f[x]);
return f[x];
}
int main(void)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
f[i]=i;
int z,x,y;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&z,&x,&y);
if(z==1)
{
int xx=fi(x);
int yy=fi(y);
f[xx]=yy;
}
else
{
int xx=fi(x);
int yy=fi(y);
if(xx==yy) cout<<"Y\n";
else cout<<"N\n";
}
}
return 0;
}