Submission #1100924

# Submission time Handle Problem Language Result Execution time Memory
1100924 2024-10-15T03:53:36 Z BuiDucManh123 Meetings 2 (JOI21_meetings2) C++14
100 / 100
261 ms 28492 KB
#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 ""
#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,int siz){
    ma[sz[id]]=max(ma[sz[id]],h);
    for(int u:g[id]){
        if(u==par||check[u]) continue;
        dfs2(u,id,h+1,siz);
    }
}
void solve(int id){
    dfs(id,0);
    int c=centroid(id,0,sz[id]);
    check[c]=1;
    dfs(c,0);
    maxdepth=0;
    for(int u:g[c]){
        if(check[u]) continue;
        dfs2(u,c,1,sz[c]-sz[u]);
        maxdepth=max(maxdepth,sz[u]);
        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*2]=max(ans[i*2],ma[i]+max(pre[i],1ll));
            pre[i]=max(pre[i],ma[i]+1);
        }
        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(!ans[i]) cout<<1<<"\n";
        else cout<<ans[i]<<"\n";
    }
	return 0;
}

Compilation message

meetings2.cpp: In function 'int main()':
meetings2.cpp:60:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   freopen(taskname".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
meetings2.cpp:61:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   freopen(taskname".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10832 KB Output is correct
2 Correct 2 ms 10832 KB Output is correct
3 Correct 2 ms 10832 KB Output is correct
4 Correct 2 ms 10832 KB Output is correct
5 Correct 2 ms 10832 KB Output is correct
6 Correct 3 ms 10836 KB Output is correct
7 Correct 2 ms 10836 KB Output is correct
8 Correct 3 ms 10836 KB Output is correct
9 Correct 2 ms 10836 KB Output is correct
10 Correct 2 ms 10836 KB Output is correct
11 Correct 2 ms 10836 KB Output is correct
12 Correct 3 ms 10836 KB Output is correct
13 Correct 2 ms 10900 KB Output is correct
14 Correct 2 ms 10836 KB Output is correct
15 Correct 2 ms 10836 KB Output is correct
16 Correct 2 ms 10836 KB Output is correct
17 Correct 3 ms 11000 KB Output is correct
18 Correct 3 ms 10912 KB Output is correct
19 Correct 2 ms 10836 KB Output is correct
20 Correct 2 ms 10836 KB Output is correct
21 Correct 2 ms 10836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10832 KB Output is correct
2 Correct 2 ms 10832 KB Output is correct
3 Correct 2 ms 10832 KB Output is correct
4 Correct 2 ms 10832 KB Output is correct
5 Correct 2 ms 10832 KB Output is correct
6 Correct 3 ms 10836 KB Output is correct
7 Correct 2 ms 10836 KB Output is correct
8 Correct 3 ms 10836 KB Output is correct
9 Correct 2 ms 10836 KB Output is correct
10 Correct 2 ms 10836 KB Output is correct
11 Correct 2 ms 10836 KB Output is correct
12 Correct 3 ms 10836 KB Output is correct
13 Correct 2 ms 10900 KB Output is correct
14 Correct 2 ms 10836 KB Output is correct
15 Correct 2 ms 10836 KB Output is correct
16 Correct 2 ms 10836 KB Output is correct
17 Correct 3 ms 11000 KB Output is correct
18 Correct 3 ms 10912 KB Output is correct
19 Correct 2 ms 10836 KB Output is correct
20 Correct 2 ms 10836 KB Output is correct
21 Correct 2 ms 10836 KB Output is correct
22 Correct 4 ms 11092 KB Output is correct
23 Correct 4 ms 10904 KB Output is correct
24 Correct 4 ms 11256 KB Output is correct
25 Correct 4 ms 11092 KB Output is correct
26 Correct 4 ms 11092 KB Output is correct
27 Correct 4 ms 11092 KB Output is correct
28 Correct 4 ms 11092 KB Output is correct
29 Correct 5 ms 11092 KB Output is correct
30 Correct 4 ms 11092 KB Output is correct
31 Correct 4 ms 11092 KB Output is correct
32 Correct 5 ms 11092 KB Output is correct
33 Correct 4 ms 11248 KB Output is correct
34 Correct 4 ms 11108 KB Output is correct
35 Correct 3 ms 11092 KB Output is correct
36 Correct 4 ms 11108 KB Output is correct
37 Correct 3 ms 11092 KB Output is correct
38 Correct 4 ms 11092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10832 KB Output is correct
2 Correct 2 ms 10832 KB Output is correct
3 Correct 2 ms 10832 KB Output is correct
4 Correct 2 ms 10832 KB Output is correct
5 Correct 2 ms 10832 KB Output is correct
6 Correct 3 ms 10836 KB Output is correct
7 Correct 2 ms 10836 KB Output is correct
8 Correct 3 ms 10836 KB Output is correct
9 Correct 2 ms 10836 KB Output is correct
10 Correct 2 ms 10836 KB Output is correct
11 Correct 2 ms 10836 KB Output is correct
12 Correct 3 ms 10836 KB Output is correct
13 Correct 2 ms 10900 KB Output is correct
14 Correct 2 ms 10836 KB Output is correct
15 Correct 2 ms 10836 KB Output is correct
16 Correct 2 ms 10836 KB Output is correct
17 Correct 3 ms 11000 KB Output is correct
18 Correct 3 ms 10912 KB Output is correct
19 Correct 2 ms 10836 KB Output is correct
20 Correct 2 ms 10836 KB Output is correct
21 Correct 2 ms 10836 KB Output is correct
22 Correct 4 ms 11092 KB Output is correct
23 Correct 4 ms 10904 KB Output is correct
24 Correct 4 ms 11256 KB Output is correct
25 Correct 4 ms 11092 KB Output is correct
26 Correct 4 ms 11092 KB Output is correct
27 Correct 4 ms 11092 KB Output is correct
28 Correct 4 ms 11092 KB Output is correct
29 Correct 5 ms 11092 KB Output is correct
30 Correct 4 ms 11092 KB Output is correct
31 Correct 4 ms 11092 KB Output is correct
32 Correct 5 ms 11092 KB Output is correct
33 Correct 4 ms 11248 KB Output is correct
34 Correct 4 ms 11108 KB Output is correct
35 Correct 3 ms 11092 KB Output is correct
36 Correct 4 ms 11108 KB Output is correct
37 Correct 3 ms 11092 KB Output is correct
38 Correct 4 ms 11092 KB Output is correct
39 Correct 171 ms 21936 KB Output is correct
40 Correct 160 ms 21580 KB Output is correct
41 Correct 161 ms 21780 KB Output is correct
42 Correct 174 ms 22104 KB Output is correct
43 Correct 173 ms 22156 KB Output is correct
44 Correct 152 ms 21800 KB Output is correct
45 Correct 261 ms 26188 KB Output is correct
46 Correct 232 ms 28492 KB Output is correct
47 Correct 75 ms 21184 KB Output is correct
48 Correct 54 ms 21948 KB Output is correct
49 Correct 145 ms 22328 KB Output is correct
50 Correct 64 ms 22612 KB Output is correct
51 Correct 151 ms 28048 KB Output is correct