为什么第一篇题解以深度为节点的默认哈希值
查看原帖
为什么第一篇题解以深度为节点的默认哈希值
554746
yiming564楼主2024/10/16 12:47

萌新看 zky 的题解 中以深度为节点的默认哈希值,为什么这能保证哈希的正确性?

题解代码:

void dfs(int x, int fa) {
	has[x] = 1ll * dep[x] * Pow[1] % mod, siz[x] = 1; // why?
	...
	L(i, 1, tot) (has[x] += 1ll * sav[i].first * Pow[siz[x]] % mod) %= mod, siz[x] += sav[i].second;
}

以及他的哈希值合并是否写错了?默认的哈希值似乎多乘了一个 Pow[1]

2024/10/16 12:47
加载中...