太离谱了! usaco考试过了 来这tle?
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const int N=100009;
int ans=0;
struct E
{
int p;
int to;
int nex;
}Edge[N*2];
int now=0;
int head[N],depth[N];
bool vis[N];
void add(int x,int y,int z)
{
Edge[++now].to=y;
Edge[now].nex=head[x];
head[x]=now;
Edge[now].p=z;
}
int dfs(int x,int parent)
{
int coun=0;
depth[x]=parent;
vis[x]=true;
for(int i=head[x];i;i=Edge[i].nex)
{
if(!vis[Edge[i].to])
{
coun++;
dfs(Edge[i].to,x);
ans++;
}
}
coun++;
ans+=ceil(log(coun)/log(2));
}
int main()
{
int n;
int a,b;
cin>>n;
for(int i=1;i<=n-1;i++)
{
cin>>a>>b;
add(a,b,1);
add(b,a,1);
}
dfs(1,0);
cout<<ans;
}