题目链接 食物链类似的题,主要是在于转化,a-b的和为s,转换为b比a-1大s.然后并查集存 此节点到根的差. 假如x的根为a,y的根为b: b - y = rank[y] a - x = rank[x] y - x = s 可以推出b - a = rank[y] - rank[x] + s; 并查集 延迟更新什么的,都忘了啊. 还有这题,如果是x--的话,记得更新0的根. #include <cstring> #include <cstdio> #include <stri…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19429 Accepted Submission(s): 6206 Problem Description Background Professor H…
wyh2000 and pupil Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 755 Accepted Submission(s): 251 Problem Description Young theoretical computer scientist wyh2000 is teaching his pupils. Wy…
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n, m; ; int fa[maxn]; int sum[maxn]; int Find(int x){ if (x == fa[x]) return x; else{ int t = fa[x]; fa[x] = Find(fa[x]); sum[x] += sum[t]; return fa[x];…