rt,写的DSU on tree,偷懒用unordered_map直接过了,然后换成gp_hash_table直接T成70了,cc_hash_table只剩45了
#define mp unordered_map<int,int>
mp dfs(int u,int f)
{
mp ret;
ret[sum[u]]=dis[u];
for(int i=0;i<a[u].size();i++)
{
int v=a[u][i].v;
if(v==f)
continue;
mp t=dfs(v,u);
if(t.size()>ret.size())
swap(t,ret);
for(auto it=t.begin();it!=t.end();it++)
{
int p=it->first,v=it->second,w=k+2*sum[u]-p;
if(ret.find(w)!=ret.end())
ans=min(ans,ret[w]+v-2*dis[u]);
}
for(auto it=t.begin();it!=t.end();it++)
{
int p=it->first;
if(ret.find(p)!=ret.end())
ret[p]=min(ret[p],it->second);
else
ret[p]=it->second;
}
}
return ret;
}