#include #include #include #include #include #include using namespace atcoder; using namespace std; vector> Graph; vector checked; pair op(pair a,pair b){ return a>b?a:b; } pair e(){ return make_pair(-1,-1); } segtree,op,e> seg; int searched=0; void _debug(){ int N=Graph.size(); for(int i=0;i p=seg.get(i); cout<<"("< tmp=seg.prod(pre,searched); if(tmp.first==-1){ break; } res+=tmp.first; seg.set(tmp.second,e()); } return res; } int main(){ int N; cin>>N; assert(1<=N && N<=200000); dsu uf(N); Graph.resize(N); checked.resize(N,false); for(int i=0;i>x>>y; assert(1<=x && 1<=y && x<=N && y<=N); assert(!uf.same(x-1,y-1)); uf.merge(x-1,y-1); Graph[x-1].push_back(y-1); Graph[y-1].push_back(x-1); } seg=segtree,op,e>(N); int ans=dfs(0); cout<