20,求助!颜色齐全!

P3367 【模板】并查集

请用 ``` 这种 ``` 样式发出来
by songyihang @ 2019-05-22 15:43:42


你的代码: ```cpp #include<bits/stdc++.h> using namespace std; struct en { int x; int y; int z; } a[10001]; int father[10001],n,m; int findc(int x); int main() { int n,m; cin>>n>>m; for(int i=1; i<=n; ++i)father[i]=i; for(int i=1; i<=m; ++i) { cin>>a[i].z>>a[i].x>>a[i].y; if(a[i].z==2) { int r1=findc(a[i].x); int r2=findc(a[i].y); if(r1==r2)cout<<"Y\n"; else cout<<"N\n"; } if(a[i].z==1)father[a[i].y]=a[i].x; } } int findc(int x) { if(x!=father[x])father[x]=findc(father[x]); return father[x]; } ```
by 三生万物 @ 2019-05-22 15:49:37


#include<bits/stdc++.h> using namespace std; struct en { int x; int y; int z; } a[10001]; int father[10001],n,m; int findc(int x); int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;++i)father[i]=i; for(int i=1;i<=m;++i) { cin>>a[i].z>>a[i].x>>a[i].y; if(a[i].z==2) { int r1=findc(a[i].x); int r2=findc(a[i].y); if(r1==r2)cout<<"Y\n"; else cout<<"N\n"; } if(a[i].z==1)father[a[i].y]=a[i].x; } } int findc(int x) { if(x!=father[x])father[x]=findc(father[x]); return father[x]; }
by 安好en @ 2019-05-22 15:49:59


下次记得用那个代码块发代码
by 三生万物 @ 2019-05-22 15:50:20


@[三生万物](/space/show?uid=116821) 谢谢,好生神奇
by 安好en @ 2019-05-22 15:50:30


@[安好en](/space/show?uid=192056) 。。。 我想说。。其实我是对楼主说的。/捂脸 不过我也没想到您刚好在我两个回复中间发了回复QAQ
by 三生万物 @ 2019-05-22 15:52:21


`1.` $a$ 数组要开到 $2\times10^{5}$ `2.` 对于 $1$ 操作最好写成 ```father[findc(a[i].y)] = findc(a[i].x);```
by shurongwang @ 2019-05-22 15:52:42


看题吧
by 安好en @ 2019-05-22 15:53:06


@[三生万物](/space/show?uid=116821) 好吧原来您就是楼主。。 ~~这回脸丢大了~~
by 三生万物 @ 2019-05-22 15:53:51


看题~~解~~吧
by songyihang @ 2019-05-22 15:53:52


| 下一页