Loading docs/dp/tree.md +63 −63 Original line number Diff line number Diff line Loading @@ -169,7 +169,7 @@ $f_v\leftarrow f_u$可以体现换根,即以$u$为根转移到以$v$为根。 于是在第二次 DFS 遍历整棵树并状态转移$f_v=f_u + n - 2 \times s_v$,那么就能求出以每个结点为根时的深度和了。最后只需要遍历一次所有根节点深度和就可以求出答案。 ??? note "参考代码" ```cppp ```cpp #include <bits/stdc++.h> using namespace std; Loading Loading
docs/dp/tree.md +63 −63 Original line number Diff line number Diff line Loading @@ -169,7 +169,7 @@ $f_v\leftarrow f_u$可以体现换根,即以$u$为根转移到以$v$为根。 于是在第二次 DFS 遍历整棵树并状态转移$f_v=f_u + n - 2 \times s_v$,那么就能求出以每个结点为根时的深度和了。最后只需要遍历一次所有根节点深度和就可以求出答案。 ??? note "参考代码" ```cppp ```cpp #include <bits/stdc++.h> using namespace std; Loading