Submission #1100902

#TimeUsernameProblemLanguageResultExecution timeMemory
1100902BuiDucManh123Meetings 2 (JOI21_meetings2)C++14
0 / 100
2 ms10972 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define taskname "meetings2" #define int ll using namespace std; ll sz[200009],ma[200009],pre[200009],i,m,n,u,v,ans[200009],check[200009],maxdepth; vector<int>g[200009]; void dfs(int id,int par){ sz[id]=1; for(int x:g[id]){ if(x==par||check[x]) continue; dfs(x,id); sz[id]+=sz[x]; } } int centroid(int id,int par,int siz){ for(int u:g[id]){ if(u==par||check[u]) continue; if(sz[u]*2>=siz) return centroid(u,id,siz); }return id; } void dfs2(int id,int par,int h){ maxdepth=max(maxdepth,sz[u]); ma[sz[id]]=max(ma[sz[id]],h); for(int u:g[id]){ if(u==par||check[u]) continue; dfs2(u,id,h+1); } } void solve(int id){ dfs(id,0); int c=centroid(id,0,sz[id]); //cout<<c<<" "; check[c]=1; dfs(c,0); //check[c]=1; maxdepth=0; for(int u:g[c]){ if(check[u]) continue; dfs2(u,c,2); for(int i=sz[u]-1;i>=1;i--) ma[i]=max(ma[i],ma[i+1]); for(int i=sz[u];i>=1;i--){ ans[i]=max(ans[i],ma[i]); ans[i]=max(ans[i],ma[i]+pre[i]-1); pre[i]=max(pre[i],ma[i]); } for(int i=1;i<=sz[u];i++) ma[i]=0; } for(int i=1;i<=maxdepth;i++) pre[i]=0; for(int u:g[c]){ if(check[u]) continue; solve(u); } } signed main() { if (fopen(taskname".inp","r")) { freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(i=1;i<n;i++){ cin>>u>>v; g[u].pb(v); g[v].pb(u); } solve(1); for(i=1;i<=n;i++){ if(i&1) cout<<1<<"\n"; else cout<<ans[i/2]<<"\n"; } return 0; }

Compilation message (stderr)

meetings2.cpp: In function 'int main()':
meetings2.cpp:63:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   freopen(taskname".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
meetings2.cpp:64:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   freopen(taskname".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...