Submission #707363

#TimeUsernameProblemLanguageResultExecution timeMemory
707363uroskMeetings 2 (JOI21_meetings2)C++14
100 / 100
413 ms72496 KiB
#define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include "bits/stdc++.h" //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll long long #define llinf 100000000000000000LL // 10^17 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pll pair<ll,ll> #define pld pair<ld,ld> #define all(a) a.begin(),a.end() #define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} #define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;} #define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); using namespace std; #define maxn 200005 #define lg 23 ll n; vector<ll> g[maxn]; vector<ll> v[maxn]; ll dub[maxn],sz[maxn]; ll st[maxn][lg]; ll in[maxn],out[maxn],ti = 0; ll ans[maxn]; void dfs(ll u,ll p){ st[u][0] = p; sz[u] = 1; in[u] = ++ti; if(u!=p) dub[u] = dub[p] + 1; else dub[u] = 0; for(ll s : g[u]){ if(s==p) continue; dfs(s,u); sz[u]+=sz[s]; } out[u] = ti-1; } ll get(ll u,ll p){ for(ll s : g[u]){ if(s==p) continue; if(sz[s]*2>=n) return get(s,u); } return u; } ll intree(ll x,ll y){return in[y]<=in[x]&&out[y]>=out[x];} ll lca(ll x,ll y){ if(intree(x,y)) return y; if(intree(y,x)) return x; for(ll j = lg-1;j>=0;j--){ if(!intree(x,st[y][j])) y = st[y][j]; } return st[y][0]; } ll dis(ll x,ll y){return dub[x] + dub[y] - 2*dub[lca(x,y)];} ll c; void tc(){ cin >> n; for(ll i = 1;i<=n-1;i++){ ll x,y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } dfs(1,1); c = get(1,1); dfs(c,c); for(ll j = 1;j<lg;j++) for(ll i = 1;i<=n;i++) st[i][j] = st[st[i][j-1]][j-1]; for(ll i = 1;i<=n;i++) v[sz[i]].pb(i); ll x = c,y = c,d = 0; for(ll i = n/2;i>=1;i--){ for(ll z : v[i]){ ll dxz = dis(x,z); ll dyz = dis(y,z); if(dxz<dyz){ swap(x,y); swap(dxz,dyz); } if(dxz>d){ d = dxz; y = z; } } ans[i] = d+1; } for(ll i = 1;i<=n;i++){ if(i&1) cout<<1<<endl; else cout<<ans[i/2]<<endl; } } int main(){ daj_mi_malo_vremena int t; t = 1; while(t--){ tc(); } return 0; } /** 5 1 2 2 3 4 2 3 5 7 1 2 2 3 3 4 4 5 2 6 3 7 **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...