题目:https://www.luogu.org/problemnew/show/P2024 自己在做本题时最大的障碍就是:不会在一个集合的father改变时把相应的补集也跟着改变. 借鉴题解后,才明白原来就是把其补集也进行合并:由于fa数组在改变,不要定义一个变量为原来的find()在后面使用. 原来的乱七八糟代码: #include<iostream> #include<cstdio> using namespace std; int n,k,s; int fa[2000005…
题意:给你n个点,m条边,然后让你使得这个这个图成为一个协和图,需要加几条边.协和图就是,如果两个点之间有一条边,那么左端点与这之间任意一个点之间都要有条边. 思路:通过并查集不断维护连通量的最大编号的节点,然后遍历即可. 代码: #include<bits/stdc++.h> using namespace std; #define int long long #define N 1005000 int f[N];int n,m; int getf(int v){// 并查集模板 if(v=…
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has a non-direct graph with n vertices and n+1 edges. Rikka can choose some of the edges (at least one…