1. 树哈希
最小表示法,进入节点为(,退出节点为)(或0与1),将儿子节点的表示法排序后,依次首尾相接。
int tot = 0;
string f[maxn], g[maxn];
void dfs(int u, int fa) {
f[u] = "0";
int tot = 0;
#define v e[i].to
for(int i = head[u]; i; i = e[i].next)
if(v != fa) dfs(v, u);
for(int i = head[u]; i; i = e[i].next)
if(v != fa) g[tot++] = f[v];
#undef v
sort(g, g+tot);
for(int i = 0; i < tot; ++i) f[u] += g[i];
f[u] += "1";
}