正文
增加 4 行删除 4 行
17 行未改动1819202122232425262728293062 行未改动9394959697989910017 行未改动Firstly we have to notice, that if $\max(v)$ denotes the highest number of tokens that can be gathered invertex $v$, then the sum of values $\max()$ for all vertices is $O(n\log n)$ (the proof is not that hard, focus onthe tree compressed to vertices with $\max() ≥ x$ and on vertices with degree $≤$ 2 in it).我不会证。然后乘上转移均摊的一个 $\log$ 总复杂度 $O(n\log^2n)$。```cpp#include<iostream>#include<cstring>#include<algorithm>62 行未改动T[u].push_back(v),T[v].push_back(u);}dfs(1,0);cout<<ans[1];return 0;}```17 行未改动1819202122232425262728293062 行未改动9394959697989910017 行未改动Firstly we have to notice, that if $\max(v)$ denotes the highest number of tokens that can be gathered invertex $v$, then the sum of values $\max()$ for all vertices is $O(n\log n)$ (the proof is not that hard, focus onthe tree compressed to vertices with $\max() ≥ x$ and on vertices with degree $≤$ 2 in it).我不会证。然后乘上转移均摊的一个 $\log$ 总复杂度 $O(n\log^2n)$。```cpp#include<iostream>#include<cstring>#include<algorithm>62 行未改动T[u].push_back(v),T[v].push_back(u);}dfs(1,0);cout<<ans[1];return 0;}```