链接 https://www.luogu.org/problemnew/show/P1551 代码 #include<bits/stdc++.h> using namespace std; #define ll long long const int maxn=1e5; int par[maxn]; int rank1[maxn]; void f(int n) //初始化 { ;i<n;i++) { par[i]=i; rank1[i]=; } } int find(int x) { i…
链接:https://ac.nowcoder.com/acm/contest/904/B 题意: DongDong每年过春节都要回到老家探亲,然而DongDong记性并不好,没法想起谁是谁的亲戚(定义:若A和B是亲戚,B和C是亲戚,那么A和C也是亲戚),她只好求助于会编程的你了. 思路: 并查集模板题. map记录人. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN =…
并查集的模板题: #include<iostream> #include<cstdio> using namespace std; ; int fa[maxn]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void unite(int x, int y) { int x1 = find(x); int y1 = find(y); if (x1 != y1)fa[x1] = y1; } int m…