大佬们来看看,全WA了,在校内OJ交就A掉了
  • 板块P1551 亲戚
  • 楼主hh弟中弟
  • 当前回复6
  • 已保存回复6
  • 发布时间2022/8/17 15:17
  • 上次更新2023/10/27 14:58:08
查看原帖
大佬们来看看,全WA了,在校内OJ交就A掉了
366639
hh弟中弟楼主2022/8/17 15:17
#include<bits/stdc++.h>
using namespace std;
int father[20086],n,m;
int find(int x){
	if(father[x]!=x)father[x]=find(father[x]);
	return father[x];
//	return find(father[x]);
}
void unionn(int x,int y){
	x=find(x);y=find(y);
	if(x==y)return;
	father[y]=x;
}
void work(){
	int x,y,c;cin>>n>>m;
	for(int i=1;i<=n;i++)father[i]=i;
	for(int i=1;i<=m;i++){
		cin>>x>>y;unionn(x,y);
	} 
	cin>>c;
	for(int i=1;i<=c;i++){
		cin>>x>>y;
		if(find(x)==find(y))cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}
int main(){
	work();
} 
2022/8/17 15:17
加载中...