#pragma region Yoyoyo #ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include using namespace std; using ll=long long; using ld=long double; using i128t=__int128_t; using pii=pair; using pll=pair; const string Yes="Yes"; const string No="No"; const long long inf=1ll<<60; #ifndef LOCAL #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define faster ios::sync_with_stdio(false);cin.tie(nullptr); #define print(s) cout< inline bool chmax(T &a,T b){return ((a inline bool chmin(T &a,T b){return ((a>b)?(a=b,true):(false));} template ll sum(const T&a){return accumulate(all(a),0LL);} template ostream &operator<<(ostream &os,const pair&p){ os< istream &operator>>(istream &is,pair&p){ is>>p.first>>p.second; return is; } template ostream &operator<<(ostream &os,const vector&v){ int s=v.size(); for(int i=0;i istream &operator>>(istream &is,vector&v){ for(auto &x:v){ is>>x; } return is; } template ostream &operator<<(ostream &os,const vector>&v){ int s=v.size(); for(int i=0;i ostream &operator<<(ostream &os,const vector>>&v){ int s=v.size(); for(int i=0;i>N; { assert(1<=N && 1<=100000); } vector>G(N); vectorcnt(N); for(int i=0;i>u>>v; {assert(1<=u && v<=N);} u--;v--; cnt[u]++;cnt[v]++; G[u].pb(v); G[v].pb(u); } {assert(*min_element(all(cnt)));} vectordp(N,{1e9,1e9}); //親依存、非親依存 a<=b auto dfs = [&](auto &&self,int s,int p)->void { //debug(s); for(auto e:G[s]){ if(e==p)continue; self(self,e,s); } //1コスを使う場合 { ll cos=1; for(auto e:G[s]){ if(e==p)continue; cos+=dp[e].fi; } chmin(dp[s].se,cos); } //1コスを使わない場合 { ll half=cnt[s]/2+1; vectorcos(0); ll afi=0; for(auto e:G[s]){ if(e==p)continue; cos.pb(dp[e].se-dp[e].fi); afi+=dp[e].fi; } sort(all(cos)); for(int i=0;i1 || s==0){ afi+=cos[half-1]; chmin(dp[s].se,afi); } } chmin(dp[s].fi,dp[s].se); }; dfs(dfs,0,-1); debug(dp); cout<