#include #include #include #include #include using namespace std; vector> Graph; vector checked; vector> vec; int dfs(int i,int parent){ checked[i]=true; for(int to:Graph[i]){ if(!checked[to]){ int p=dfs(to,i); vec[i].push(p); } } int max_size=vec[i].size(); int id=i; for(int to:Graph[i]){ if(to!=parent){ if(vec[to].size()>max_size){ id=to; max_size=vec[to].size(); } } } if(id!=i){ while(!vec[i].empty()){ vec[id].push(vec[i].top()); vec[i].pop(); } } for(int to:Graph[i]){ if(id!=to && to!=parent){ while(!vec[to].empty()){ vec[id].push(vec[to].top()); vec[to].pop(); } } } vec[i].swap(vec[id]); int res=1; if(vec[i].size()<=2){ while(!vec[i].empty()){ res+=vec[i].top(); vec[i].pop(); } }else{ for(int j=0;j<2;j++){ res+=vec[i].top(); vec[i].pop(); } } return res; } int main(){ int N; cin>>N; Graph.resize(N); checked.resize(N,false); vec.resize(N); for(int i=0; i>x>>y; Graph[x-1].push_back(y-1); Graph[y-1].push_back(x-1); } int ans=dfs(0,-1); cout<