#include<bits/stdc++.h>
#define N 100100
using namespace std;
const int INF=1008610086;
int A[N],B[N],C[N];
int beg[N],to[N],nex[N];
int n,len;
inline void Add(int a,int b){
nex[++len]=beg[a],beg[a]=len,to[len]=b;
nex[++len]=beg[b],beg[b]=len,to[len]=a;
}
void dfs(int p,int fa){
A[p]=B[p]=C[p]=0;
int mib=1;
int f=0;
for(int i=beg[p];i;i=nex[i]){
if(to[i]==fa) continue;
dfs(to[i],p);
if(A[to[i]]<=B[to[i]]){
A[p]+=A[to[i]];
mib=min(mib,B[to[i]]-A[to[i]]);
}
else A[p]+=B[to[i]],f=1;
C[p]+=min(B[to[i]],A[to[i]]);
B[p]+=min(C[to[i]],min(B[to[i]],A[to[i]]));
}
B[p]++;
if(!f) A[p]+=mib;
if(!A[p]) A[p]=1;
}
int main(){
scanf("%d",&n);
for(int i=1;i<n;i++){
int a,b;
scanf("%d%d",&a,&b);
Add(a,b);
}
dfs(1,0);
printf("%d\n",min(A[1],B[1]));
return 0;
}
洛谷P2899 [USACO08JAN]手机网络Cell Phone Network
最新推荐文章于 2022-12-03 21:20:21 发布