Submission #1042080

#TimeUsernameProblemLanguageResultExecution timeMemory
1042080pccMeetings 2 (JOI21_meetings2)C++17
100 / 100
441 ms34424 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 4e5+10; vector<int> tree[mxn]; bitset<mxn> del; int sz[mxn],dep[mxn]; int N; int ans[mxn]; struct BIT{ int bit[mxn]; int s; void resize(int n){ s = n; fill(bit,bit+s+1,-mxn); } void modify(int p,int v){ p = s-p; assert(p>0); for(;p<s;p+=p&-p)bit[p] = max(bit[p],v); } int getval(int p){ p = s-p; int re = -mxn; for(;p>0;p-= p&-p)re = max(re,bit[p]); return re; } }; BIT bit; void szdfs(int now,int par){ sz[now] = 1; for(auto nxt:tree[now]){ if(nxt == par||del[nxt])continue; szdfs(nxt,now); sz[now] += sz[nxt]; } return; } int find_centroid(int now,int par,int tar){ for(auto nxt:tree[now]){ if(nxt == par||del[nxt])continue; if(sz[nxt]>tar)return find_centroid(nxt,now,tar); } return now; } void dfs(int now,int par,int psz){ if(now == par)dep[now] = 1; for(auto nxt:tree[now]){ if(nxt == par||del[nxt])continue; dep[nxt] = dep[now]+1; dfs(nxt,now,psz); } int pos = sz[now]; ans[pos*2] = max(ans[pos*2],dep[now]+bit.getval(pos)+1); ans[min(psz,pos)*2] = max(ans[min(psz,pos)*2],dep[now]+1); return; } void dfs2(int now,int par){ bit.modify(sz[now],dep[now]); for(auto nxt:tree[now]){ if(nxt == par||del[nxt])continue; dfs2(nxt,now); } return; } void cd(int now,int par){ dep[now] = 0; szdfs(now,now); bit.resize(sz[now]+3); now = find_centroid(now,now,(sz[now]-1)>>1); szdfs(now,now); del[now] = true; for(auto nxt:tree[now]){ if(del[nxt])continue; dep[nxt] = 1; dfs(nxt,nxt,N-sz[nxt]); dfs2(nxt,nxt); } bit.resize(sz[now]+3); for(auto it = tree[now].rbegin();it != tree[now].rend();it++){ int nxt = *it; if(del[nxt])continue; dep[nxt] = 1; dfs(nxt,nxt,N-sz[nxt]); dfs2(nxt,nxt); } for(auto nxt:tree[now]){ if(!del[nxt])cd(nxt,now); } return; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N; fill(ans,ans+N+1,1); for(int i = 1;i<N;i++){ int a,b; cin>>a>>b; tree[a].push_back(b); tree[b].push_back(a); } cd(1,1); for(int i = N;i>=1;i--)ans[i] = max(ans[i],ans[i+1]); for(int i = 1;i<=N;i+=2)ans[i] = 1; for(int i = 1;i<=N;i++)cout<<ans[i]<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...