什么也不用说,并查集裸题,直接盲敲即可. #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cctype> #include <cmath> #include <algorithm> #include <numeric> using namespace std; ]; int getFath…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other,…
裸敲并查集,很水一次AC #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cctype> #include <cmath> #include <algorithm> #include <numeric> #include <string> #pragma comment(lin…
裸并查集,但有二坑: 1.需要路径压缩,不写的话会TLE 2.根据题目大意,如果0组男孩合作的话,应该最大的子集元素数目为1.所以res初始化为1即可. #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <algorithm> #include <numeric> #include <string> #i…
仍旧裸敲并查集.有这两点注意: 1.输入 0 0 时候要输出YES 2.留心数组的初始化 #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <numeric> #include <algorithm> #include <cctype> #include <string> using name…
查环操作,裸题.一次AC. #include <iostream> #include <cstring> #include <cstdlib> #include <cctype> #include <cmath> #include <string> #include <cstdio> #include <algorithm> #include <numeric> using namespace st…
有以下坑点: 1.结束输入不一定-1,题目中的叙述只是说所有权值都为正值. 2.是否构成一棵树不能只判断是否只有一个根节点,没有环路,而且还需要判断每个节点的入度一定是1,不然就不是一棵树. (无环路也可用树的性质:结点数 = 边树 + 1 来取代) #include <iostream> #include <cstdlib> #include <cstring> #include <cctype> #include <cmath> #inclu…
https://vjudge.net/problem/POJ-1182 并查集经典题 对于每只动物创建3个元素,x, x+N, x+2*N(分别表示x属于A类,B类和C类). 把两个元素放在一个组代表他们同时发生. 被不合法数据卡了几次. #include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #include<cma…
如题... #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; /* 并查集水题 */ +; struct UF{ int father[maxn]; void init(){ ;i<maxn;i++) father[i]=i; } int find_root(int x){ if(father[x]!=x…
G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u CodeForces 690C1 Description One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know…