随笔分类 -  并查集

【codeforces 19/11/06 div2】D. 0-1 MST
摘要:1 #include<iostream> 2 #include<set> 3 #include<map> 4 #include<queue> 5 #include<algorithm> 6 using namespace std; 7 8 const int maxn = 100010; 9 int 阅读全文
posted @ 2019-11-09 00:17 thjkhdf12 阅读(143) 评论(0) 推荐(0)
【模板】并查集
摘要:1 const int maxn = 100010; 2 int fa[maxn]; 3 4 int find(int x) 5 { 6 if (fa[x] == x) return x; 7 fa[x] = find(fa[x]); 8 return fa[x]; 9 } 10 11 void merge(int a, int b) 12 { 13... 阅读全文
posted @ 2019-10-09 13:59 thjkhdf12 阅读(95) 评论(0) 推荐(0)
P1197 [JSOI2008]星球大战
摘要:1 #include<iostream> 2 #include<cstring> 3 #define debug(i) cout<<"(i): "<<i<<endl 4 using namespace std; 5 6 int fa[400010]; 7 8 int find(int x) 9 { 阅读全文
posted @ 2019-10-09 13:51 thjkhdf12 阅读(107) 评论(0) 推荐(0)
【种类并查集】P2024 [NOI2001]食物链
摘要:1 #include<iostream> 2 using namespace std; 3 4 int fa[150010]; 5 int n, k; 6 int cnt; 7 8 int find(int x) 9 { 10 if (x == fa[x]) return x; 11 fa[x] = 阅读全文
posted @ 2019-10-09 13:51 thjkhdf12 阅读(95) 评论(0) 推荐(0)
P3367 【模板】并查集
摘要:1 #include<iostream> 2 using namespace std; 3 int b[10010]; 4 5 int find(int n) 6 { 7 if (b[n] == n) return n; 8 return b[n] = find(b[n]); 9 } 10 int 阅读全文
posted @ 2019-10-09 13:49 thjkhdf12 阅读(96) 评论(0) 推荐(0)
P1111 修复公路
摘要:1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 int fa[1010]; 6 int n, m; 7 8 int find(int x) 9 { 10 if (fa[x] == x) return x; 1 阅读全文
posted @ 2019-10-09 13:48 thjkhdf12 阅读(125) 评论(0) 推荐(0)
P1525 关押罪犯
摘要:1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 int fa[20010]; 6 7 int find(int x) 8 { 9 if (x == fa[x]) 10 return x; 11 fa[x] = 阅读全文
posted @ 2019-10-09 13:42 thjkhdf12 阅读(120) 评论(0) 推荐(0)
【Kruskal】P1991 无线通讯网
摘要:1 #include<iostream> 2 #include<algorithm> 3 #include<cmath> 4 #include<iomanip> 5 using namespace std; 6 7 int fa[501]; 8 9 int find(int x) 10 { 11 i 阅读全文
posted @ 2019-10-09 13:36 thjkhdf12 阅读(112) 评论(0) 推荐(0)
【Kruskal】P2330 [SCOI2005]繁忙的都市
摘要:1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 int fa[301]; 6 7 int find(int x) 8 { 9 if (x == fa[x]) return x; 10 fa[x] = find 阅读全文
posted @ 2019-10-09 13:35 thjkhdf12 阅读(98) 评论(0) 推荐(0)
【Kruskal】P1546 最短网络 Agri-Net
摘要:1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 int fa[200010]; 6 int n; 7 int cnt; 8 9 struct Edge 10 { 11 int u, v, w; 12 bool 阅读全文
posted @ 2019-10-09 13:34 thjkhdf12 阅读(122) 评论(0) 推荐(0)