lzqy_ @ 2020-03-03 20:44:07
上代码~
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(3,"Ofast","inline")
int a[10001];
void chu(int n)
{
for(int i=1; i<=n; i++)
a[i]=i;
}
int ru2(int y)
{
if(a[y]==y)
{
return y;
}
else
{
a[y]=ru2(a[y]);
}
}
int main()
{
int n,m,p,x,y,z;
scanf("%d%d",&n,&m);
chu(n);
for(int i=1; i<=m; i++)
{
scanf("%d%d%d",&z,&x,&y);
if(z==1)
a[ru2(y)]=ru2(x);
else if(ru2(x)!=ru2(y))
{
printf("N\n");
}
else
{
printf("Y\n");
}
}
return 0;
}
跪求大佬~
应该没问题吧。。。。。。
by Zxx200611 @ 2020-03-03 20:45:42
int ru2(int y)
{
if(a[y]==y)
{
return y;
}
else
{
a[y]=ru2(a[y]);
}
}
改成
int ru2(int y)
{
if(a[y]==y)
{
return y;
}
else
{
return a[y]=ru2(a[y]);
}
}
by Kinandra @ 2020-03-03 20:46:05
你的ru2没返回值
by Kinandra @ 2020-03-03 20:46:21
2l说得对
by lzqy_ @ 2020-03-03 20:47:16
谢谢大佬们!!
(真心感谢,改了一晚上了)