```
if(pre[root]=root)
```
不应该是==吗QAQ~~鬼知道我怎么看下去的~~
by Dirt、 @ 2019-04-18 19:18:01
@[2018J1605](/space/show?uid=143834) 还是不行...
by vivaEleanor @ 2019-04-18 19:18:52
@[2018J1605](/space/show?uid=143834) 只能输入2行
by vivaEleanor @ 2019-04-18 19:19:39
还有 if(zi=1) 不应该也是==吗
by yyk504 @ 2019-04-18 19:20:47
@[yyk504](/space/show?uid=128874) *嗷嗷嗷
by vivaEleanor @ 2019-04-18 19:21:26
亲, 建议您先学好语言再开算法哦>_<
by Juan_feng @ 2019-04-18 19:21:57
现在是
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int N,M;
int pre[10010];
int zi,xi,yi;
int find(int root)
{
if(pre[root]==root)return root;
return pre[root]=find(pre[root]);
}
void join(int root1,int root2){
int x,y;
x=find(root1);
y=find(root2);
if(x!=y) pre[x]=y; //合并
}
int main(){
cin>>N>>M;
cin>>zi>>xi>>yi;
int i,j;
int t1,t2;
if(zi==1){join(xi,yi);}
else {
t1=find(xi) ;
t2=find(yi);
if(t1==t2){cout<<"Y"<<endl;}
else{cout<<"N"<<endl;}
return 0;
}
}
只有*一个输出
by vivaEleanor @ 2019-04-18 19:24:07
您并没有用for啊
~~建议重修~~ 重新读题
by LJB00131 @ 2019-04-18 19:25:23
@[LJB00131](/space/show?uid=54544)
大佬,求助
by vivaEleanor @ 2019-04-18 19:26:20
多组操作啊
by LJB00131 @ 2019-04-18 19:27:49