比赛 |
板子大赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
亲戚关系 |
最终得分 |
100 |
用户昵称 |
喵喵喵 |
运行时间 |
1.136 s |
代码语言 |
C++ |
内存使用 |
3.40 MiB |
提交时间 |
2025-01-22 10:28:48 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N = 20010;
int n,m;
int f[N];
void init()
{
for(int i = 1;i <= N;i++)
{
f[i] = i;
}
}
int get(int x)
{
if(x == f[x]) return x;
return f[x] = get(f[x]);
}
void merge(int x, int y)
{
int fx = get(x), fy = get(y);
if(fx != fy) f[fy] = fx;
}
int main()
{
freopen("relation.in","r",stdin);
freopen("relation.out","w",stdout);
init();
cin >> n >> m;
for(int i = 1;i <= m;i++)
{
int op,x,y;
cin >> op >> x >> y;
if(op == 0)
merge(x,y);
else
{
if(get(x) == get(y)) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
}