这种东西看代码比说话好用。
#include<bits/stdc++.h>
#define int long long
#define ull unsigned
#define up(i,l,r) for(int i=l; i<=r; ++i)
#define dn(i,r,l) for(int i=r; i>=l; --i)
#define pb push_back
using namespace std;
const int N=111;
const ull mask=std::chrono::steady_clock::now().time_since_epoch().count();
int ull shift(ull x) {
x^=mask, x^=x<<13, x^=x>>7, x^=x<<17, x^=mask;
return x;
}
int t, n, rt, siz[N]; ull hsh[N];
vector<int> to[N], heart; set<int> trees, qwq;
void dp(int x,int fa) {
int ms=0; siz[x]=1;
for(int y:to[x]) if(y^fa) dp(y,x), siz[x]+=siz[y], ms=max(ms,siz[y]);
ms=max(ms,n-siz[x]);
if(ms<=n/2) heart.pb(x);
}
void Hash(int x,int fa) {
hsh[x]=1;
for(int y:to[x]) if(y^fa) Hash(y,x), hsh[x]+=shift(hsh[y]);
trees.insert(hsh[x]);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
up(i,2,n) {
int u, v; cin >> u >> v;
to[u].pb(v), to[v].pb(u);
}
heart.clear(), dp(1,0);
for(int rt:heart) {
trees.clear(), Hash(rt,0);
qwq=max(trees,qwq);
}
// jury hash is qwq.
return 0;
}
标签:哈希,int,siz,ull,ms,qwq,define
From: https://www.cnblogs.com/chelsyqwq/p/18107158