求调
查看原帖
求调
1226821
lxr00000楼主2025/6/26 10:55

为什么全RE?

#include<bits/stdc++.h>
using namespace std;
int n,m,z,x,y,f[200005];
int find(int d)
{
	int t0=d;
	while(f[t0]!=t0)
	{
		t0=f[t0];
	}
	f[d]=t0;
	return f[d];
}
int hebin(int x1,int x2)
{
	f[find(x1)]=x2;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		f[i]=i;
	}
	for(int i=1;i<=m;i++)
	{
		cin>>z>>x>>y;
		if(z==1)
		{
			hebin(x,y);
		} 
		else
		{
			if(find(x)==find(y))
			{
				cout<<"Y\n";
			}
			else
			{
				cout<<"N\n";
			}
		}
	}
} 
2025/6/26 10:55
加载中...