C. Game on Tree
单独考虑每个点对答案的贡献。
删除一个点的方案是删除它或者它的祖先,那么对答案的贡献是1depu\frac 1 {\text{dep}_u}depu1
#include<cstdio>
#include<vector>int n;
std::vector<int> g[100005];
int dep[100005];
void dfs(int u,int fa)
{dep[u]=dep[fa]+1;for(auto v:g[u]){if(v==fa) continue;dfs(v,u);}
}
int main()
{scanf("%d",&n);for(int i=1;i<=n;i++){int u,v;scanf("%d%d",&u,&v);g[u].push_back(v);g[v].push_back(u);}dfs(1,0);double ans=0;for(int i=1;i<=n;i++) ans+=1.0/dep[i];printf("%.7lf\n",ans);return 0;
}