怎么0分了怎么全WA了
  • 板块P1551 亲戚
  • 楼主xieguiren1
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/7/23 15:26
  • 上次更新2023/10/27 18:46:26
查看原帖
怎么0分了怎么全WA了
756595
xieguiren1楼主2022/7/23 15:26

代码:

#include <cstdio>
#include <iostream>
using namespace std;
#define MAXSIZE 5001
int father[MAXSIZE];
void init(int a){
	father[a]=a;
}
int find(int a){
	if(father[a]==a) return a;
	return father[a]=find(father[a]);
}
void unionn(int a,int b){
	father[find(b)]=find(a);
	return ;
}
int main(){
	int n,m,p;
	int a,b;
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++) father[i]=i;
	for(int i=1;i<=m;i++){
		cin>>a>>b;
		unionn(a,b);
	}
	for(int i=1;i<=p;i++){
		cin>>a>>b;
		if(find(a)==find(b)) cout<<"Yes";
		else cout<<"No";
	}
   return 0;
}
2022/7/23 15:26
加载中...