为何20分

P3367 【模板】并查集

仙人求我 @ 2018-03-03 16:57:05

include<iostream>

using namespace std; const int MAXN=1000001; int m,n,zi,xi[MAXN],yi[MAXN],fa[MAXN]; int find(int x) { return x==fa[x]?x:(fa[x]=find(fa[x])); } int join(int u,int v) { int u1=find(u),v1=find(v); if(u1!=v1) { fa[u]=v; return 0; } } int judge(int u,int v) { int u1=find(u),v1=find(v); if(u1==v1) cout<<"Y"<<endl; else cout<<"N"<<endl; } int main() { cin>>n>>m; for(int i=1;i<=n;i++) fa[i]=i; for(int i=1;i<=m;i++) { cin>>zi>>xi[i]>>yi[i]; if(zi==1) join(xi[i],yi[i]); else if(zi==2) judge(xi[i],yi[i]); } return 0; }


by AThousandSuns @ 2018-03-03 17:05:11

请使用

```cpp

```

把代码括起来


by 小闸蟹 @ 2018-03-03 17:07:03

join里面应该是拿祖先合并@AlphaTrump


|