#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_back(p); } } int res=1; sort(vec[i].rbegin(),vec[i].rend()); if(vec[i].size()<=2){ for(int j:vec[i]){ res+=j; } }else{ for(int j=0;j<2;j++){ res+=vec[i][j]; } if(parent!=-1){ for(int j=2;j>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<