這題就是無腦,萌新不知道什麼叫樹的重心,也不知道什麼叫最小表示法排序,萌新只會無腦hash
對每一棵樹,每乙個節點為根跑一次hash值,強行判斷就好
最後用並查集維護一下,其他看**吧
#include
#include
#include
#include
#include
#include
using
namespace std;
const
int mod =
1e9+7;
const
int jinzhi =
251;
const
int maxn =
101;
const
int mk =
101;
const
int p =
19260817
;typedef
long
long ll;
struct node
edge[mk]
[maxn*2]
;int cnt[mk]
,head[mk]
[maxn]
,n,m,val[maxn]
,tot,f[maxn]
;long
long size[mk]
[maxn]
[maxn]
,dep[mk]
[maxn]
[maxn]
,hbsh[mk]
[maxn]
[maxn]
;struct _hash
hash[maxn]
;priority_queue<
int> q[maxn]
;void
add(
int from,
int to,
int k)
intfind
(int x)
intmerge
(int a,
int b)
void
dfs(
int u,
int fa,
int k,
int root)
hbsh[k]
[root]
[u]=
(ll)size[k]
[root]
[u]*
(ll)p%mod*
(ll)dep[k]
[root]
[u]%mod;
}bool
cmp1
(int a,
int b)
bool
check
(ll a[
],ll b,
int size1,
int size2)
return
true;}
intmain()
}for
(int i=
1;i<=m;i++
)for
(int j=
1;j<=val[i]
;j++
)dfs
(j,0
,i,j)
,sort
(hbsh[i]
[j],hbsh[i]
[j]+val[i]+2
,cmp1)
;for
(int i=
1;i<=m;i++
)for
(int j=
1;j<=val[i]
;j++
)for
(int k=
1;k<=val[i]
;k++
) hash[i]
.hbsh[j]
=(hash[i]
.hbsh[j]
*jinzhi+hbsh[i]
[j][k]
)%mod,hash[i]
.pos=i;
for(
int i=
1;i<=m;i++
)for
(int j=
1;j<=val[i]
;j++
)sort
(hash[i]
.hbsh+
1,hash[i]
.hbsh+
1+val[i]
,cmp1)
;for
(int i=
1;i<=m;i++)}
for(
int i=
1;i<=m;i++
) cout<<
find
(i)<}
樹 洛谷 P1087 FBI樹
我們可以把由 0 和 1 組成的字串分為三類 全 0 串稱為b串,全 1 串稱為i串,既含 0 又含 1 的串則稱為f串。fbi樹是一種二叉樹,它的結點型別也包括f結點,b結點和i結點三種。由乙個長度為2 n的 01 串s可以構造出一棵fbi樹t,遞迴的構造方法如下 1 t的根結點為r,其型別與串s...
洛谷 P5889 跳樹
大體思路很簡單,用線段樹維護區間操作,詢問便是區間查詢即可 真正有難度的地方在於操作區間合併,比較難理解。注意,中寫的運算子過載只能運用於先進行的操作 後進行的操作 操作區間合併對我這樣的蒟蒻還是挺難理解的 sys orz.include include include include includ...
洛谷P5829 失配樹
給定一長為 n n leq 10 6 的字串 s m m leq 5 times 10 5 次詢問,每次詢問它的兩個字首的最長公共 border。先跑一遍kmp求出 fail 陣列,每個 pos 向 fail pos 連邊,建出 fail 樹,在 fail 樹上求lca即為兩個字首的最長公共bord...