吸了氧还是超时3个
#include<bits/stdc++.h>
using namespace std;
int n, m;
int p[10001];
int find(int t)
{
int y;
y = p[t];
while(p[y] != y)
{
y = p[y];
}
return(y);
}
void Union(int x, int y)
{
int f1, f2;
f1 = find(x);
f2 = find(y);
p[f1] = f2;
}
int main()
{
int i;
int num;
int x, y;
int f1, f2;
cin >> n >> m;
for(i = 1; i <= n; i++)
{
p[i] = i;
}
for(i = 0; i < m; i++)
{
cin >> num >> x >> y;
if(num == 2)
{
f1 = find(x);
f2 = find(y);
if(f1 == f2)
{
cout << 'Y';
}
else
{
cout << 'N';
}
cout << endl;
}
else
{
Union(x, y);
}
}
}