Submission #1300609

#TimeUsernameProblemLanguageResultExecution timeMemory
1300609Zbyszek99Meetings 2 (JOI21_meetings2)C++20
100 / 100
70 ms31468 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vl vector<long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll los(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; int ans[200001]; vi graph[200001]; int sub[200001]; int depth[200001]; vi dp[200001]; void dfs(int v, int pop, int d) { depth[v] = d++; sub[v] = 1; forall(it,graph[v]) { if(it != pop) { dfs(it,v,d); sub[v] += sub[it]; } } } void dfs_dp(int v, int pop) { depth[v] = depth[pop]+1; sub[v] = 1; int cnt = 0; int fff = -1; forall(it,graph[v]) if(it != pop) { dfs_dp(it,v); sub[v] += sub[it]; fff = it; cnt++; } if(v != pop) { ans[sub[v]*2] = max(ans[sub[v]*2],depth[v]); } if(cnt == 0) { dp[v].pb(depth[v]); return; } swap(dp[v],dp[fff]); forall(it,graph[v]) { if(it == fff || it == pop) continue; if(siz(dp[v]) < siz(dp[it])) { swap(dp[v],dp[it]); } rep(j,siz(dp[it])) { ans[(j+1)*2] = max(ans[(j+1)*2],dp[v][j]+dp[it][j]-2*depth[v]+1); dp[v][j] = max(dp[v][j],dp[it][j]); } } while(siz(dp[v]) < sub[v]) { dp[v].pb(depth[v]); } } inline int fastRead() { int x = 0, c = getchar_unlocked(); while (c < '0' || c > '9') c = getchar_unlocked(); while (c >= '0' && c <= '9') { x = x * 10 + (c - '0'); c = getchar_unlocked(); } return x; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //random_start(); int n = fastRead(); ans[n] = 1; rep(i,n-1) { int a = fastRead(),b = fastRead(); graph[a].pb(b); graph[b].pb(a); } dfs(1,1,0); int centr = 1; int pop = -1; while(true) { pii best = {-1e9,-1}; forall(it,graph[centr]) { if(it != pop) best = max(best,{sub[it],it}); } if(best.ff > n/2) { pop = centr; centr = best.ss; } else break; } depth[centr] = 0; dfs_dp(centr,centr); for(int i = n-1; i >= 1; i--) { ans[i] = max(ans[i],ans[i+1]); } rep2(i,1,n) if(i % 2 == 1) cout << "1\n"; else cout << ans[i] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...