记录编号 |
600079 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
亲戚 |
最终得分 |
100 |
用户昵称 |
郑霁桓 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.161 s |
提交时间 |
2025-04-15 20:03:00 |
内存使用 |
3.80 MiB |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
long long n,m,x,y,fa[20005];
long long f(long long x){
if(fa[x]!=x){
fa[x]=f(fa[x]);
}
return fa[x];
}
int main(){
freopen("relations.in","r",stdin);
freopen("relations.out","w",stdout);
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++){
fa[i]=i;
}
for(int i=1;i<=m;i++){
scanf("%lld%lld",&x,&y);
fa[f(x)]=f(y);
}
scanf("%lld",&m);
while(m--){
scanf("%lld%lld",&x,&y);
if(f(x)==f(y)){
printf("Yes");
}else{
printf("No");
}
}
return 0;
}