大佬求求教教我吧!!!!!!!!!
  • 板块P1551 亲戚
  • 楼主liyx13
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/8/24 14:39
  • 上次更新2024/8/24 16:48:49
查看原帖
大佬求求教教我吧!!!!!!!!!
1278673
liyx13楼主2024/8/24 14:39

不知道为啥输出 6 5 3

		1 2
		1 5
		3 4
		5 2
		1 3
		1 4
		s
		2 3
		s
		5 6
		o
c++
#include<bits/stdc++.h>

struct uniofind{
	int bin[100005];   
	uniofind(){
		for(int i=1;i<=100002;i++)
		bin[i]=i;
	}
	int anc(int x){
		 if(bin[x]==x) return x;
		 return anc(bin[x]);
	}
	void uni(int x,int y){
		bin[anc(x)]=anc(y);
	}
	void ask(int x,int y){
		printf("%c\n",anc(x)==anc(y) ?'Yes':'No');  
	}  
};
uniofind u;
int main(void){
	int n,m,p;
	int x,y;
	scanf("%d%d%d",&n,&m,&p);
	while(m--)
	{
		scanf("%d%d",&x,&y);
		u.uni(x,y);
	}
	while(p--)
	{
		scanf("%d%d",&x,&y);
		u.ask(x,y);
     }
	return 0;
}
``		(o o)
球求拉 (| |)
2024/8/24 14:39
加载中...