并查集板子

 1 /**
 2  *  Fuck you.
 3  *  I love you too.
 4  */
 5 
 6 #include<bits/stdc++.h>
 7 #define lson i<<2
 8 #define rson i<<2|1
 9 #define LS l,mid,lson
10 #define RS mid+1,r,rson
11 #define mem(a,x) memset(a,x,sizeof(a))
12 #define gcd(a,b) __gcd(a,b)
13 #define ll long long
14 #define ull unsigned long long
15 #define lowbit(x) (x&-x)
16 #define enld endl
17 #define mian main
18 #define itn int
19 #define prinft printf
20 
21 const double PI = acos (-1.0);
22 const int INF = 0x3f3f3f3f;
23 const int EXP = 1e-8;
24 const int N = 1e5 + 5;
25 const int MOD = 1e9 + 7;
26 const int MAXN = 1e5 + 5;
27 
28 using namespace std;
29 
30 int par[N];
31 
32 void init() {
33     for (int i = 1; i <= N; i++)
34         par[i] = i;
35 }
36 
37 int Find (int a) {
38     return a == par[a] ? a : par[a] = Find (par[a]);
39 }
40 
41 void join (int a, int b) {
42     par[Find (a)] = Find (b);
43 }
44 
45 
46 int main() {
47     init();
48     for (int i = 1; i <= 10; i++) {
49         join (i, i + 1);
50     }
51     Find (1);
52     for (int i = 1; i <= 10; i++) {
53         cout << par[i] << ' ';
54     }
55     return 0;
56 }
View Code

 

转载于:https://www.cnblogs.com/chunibyo/p/9407066.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值