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 mytester @ 2019-04-18 19:48:01

神鱼过分了啊


by NaCly_Fish @ 2019-04-18 19:49:20

@yyk504 就是个LCT啊 qwq


by Zenurik @ 2019-04-18 19:50:07

@vivaEleanor 从您的提交记录来看,不建议现阶段学习并查集。学习要一步一步来的。

话说您这种行为就好像我一同学连BST都没学会就去搞LCT一样


by aminoas @ 2019-04-18 19:50:08

额,lz好像就是之前问我最长非升子序列的那个...


by yyk504 @ 2019-04-18 19:51:57

@NaCly_Fish 还在攻LCA。。。(离LCT还远)


by yyk504 @ 2019-04-18 19:52:39

@NaCly_Fish 难怪看不懂。。。


by vivaEleanor @ 2019-04-18 20:53:14


#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; 
    int i,j;
    for(i=1;i<=N;i++) pre[i]=i; 
    for(i=1;i<=M;i++){
        cin>>zi>>xi>>yi;
         if(zi==1){join(xi,yi);}

        else if(zi==2){
            int t1,t2;
            t1=find(xi);t2=find(yi);
            if(t1==t2) 
                cout<<"Y"<<endl;
            else 
                cout<<"N"<<endl;    
            } 
    } 
           return 0;    

}

我终于A了~~~~


by vivaEleanor @ 2019-04-18 20:54:40

谢谢大佬们,即使你们的话好伤人,嘤嘤


by si_zhong @ 2019-05-07 20:51:05

我帮你

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 午夜星辰丶饬 @ 2019-07-17 10:27:27

希望更丰富的展现?使用Markdown


上一页 | 下一页