# [AIZU2784]Similarity of Subtrees（树Hash）

### Description

Define the depth of a node in a rooted tree by applying the following rules recursively:

Let S(T,d) be the number of nodes of T with depth d. Two rooted trees T and T′ are similar if and only if S(T,d) equals S(T′,d) for all non-negative integer d
You are given a rooted tree Twith N nodes. The nodes of T are numbered from 1 to N. Node 1 is the root node of T. Let Ti be the rooted subtree of T whose root is node i. Your task is to write a program which calculates the number of pairs (i,j) such that Ti and Tj are similar and i<j.

## 解决思路

$Hash[u]=\sum Hash[v]*base$

HNCJ OIer