SOS!!!!!SOS!!!!!HELP!!!!HELP!!!!

P3367 【模板】并查集

vivaEleanor @ 2019-04-18 19:10:32

那位大佬能告诉蒟蒻我这有什么问题....

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 Dirt、 @ 2019-04-18 19:18:01

 if(pre[root]=root)

不应该是==吗QAQ鬼知道我怎么看下去的


by vivaEleanor @ 2019-04-18 19:18:52

@2018J1605 还是不行...


by vivaEleanor @ 2019-04-18 19:19:39

@2018J1605 只能输入2行


by yyk504 @ 2019-04-18 19:20:47

还有 if(zi=1) 不应该也是==吗


by vivaEleanor @ 2019-04-18 19:21:26

@yyk504 *嗷嗷嗷


by Juan_feng @ 2019-04-18 19:21:57

亲, 建议您先学好语言再开算法哦>_<


by vivaEleanor @ 2019-04-18 19:24:07

现在是

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 LJB00131 @ 2019-04-18 19:25:23

您并没有用for啊

建议重修 重新读题


by vivaEleanor @ 2019-04-18 19:26:20

@LJB00131 大佬,求助


by LJB00131 @ 2019-04-18 19:27:49

多组操作啊


上一页 | 下一页