并查集
FAUX123455
这个作者很懒,什么都没留下…
展开
-
E. Split Into Two Sets(种类并查集)(Codeforces Round #805 (Div. 3))
用种类并查集维护冲突关系。原创 2022-07-11 09:55:01 · 379 阅读 · 0 评论 -
D. Social Network( Deltix Round, Autumn 2021 (open for everyone, rated, Div. 1 + Div. 2)并查集)
链接. 不懂为什么这么水的代码wa了一晚上… 把大佬的题解贴过来 题解. #include<bits/stdc++.h> using namespace std; int n,d; int f[1010],k[1010]; int get(int x) { return x==f[x]?x:f[x]=get(f[x]); } bool cmp(int x,int y) { return x>y; } int main() { ios::sync_with_s原创 2021-11-30 13:35:34 · 858 阅读 · 0 评论 -
C. String Reconstruction(Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals))
链接:link. 并查集优化可避免重复赋值。 int n,f[2000050]; char s[2000050],t[1000010]; int g(int x){return x==f[x]?x:f[x]=g(f[x]);} int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); for(int i=0;i<=2000000;i++)f[i]=i; int len=0; cin>>原创 2021-09-28 17:26:32 · 56 阅读 · 0 评论 -
D. Harmonious Graph(Codeforces Round #600 (Div. 2)
链接:link. 题意:n个点,m条边,求要满足:如果l能到r,l也要能到l+1,l+2…,r-1至少要增加几条边。 思路:并查集储存当前连通图的最大点. int n,m; int f[200010]; int g(int x){return x==f[x]?x:f[x]=g(f[x]);} int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n>>m; for(int原创 2021-09-16 09:41:18 · 66 阅读 · 0 评论 -
并查集(kuangbing专题)
1.Wireless Network POJ - 2236 int n,D,d[1010][1010]; int f[1010],ff[1010]; struct node{int x,y;}w[1010]; int get(int x){return x==f[x]?x:f[x]=get(f[x]);} int main() { scanf("%d%d",&n,&D); D=D*D; for(int i=1;i<=n;i++)scanf("%d%d",&原创 2021-08-20 16:14:00 · 86 阅读 · 0 评论