답안 #532874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532874 2022-03-04T06:58:59 Z Koosha_mv Meetings 2 (JOI21_meetings2) C++14
100 / 100
589 ms 25808 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=2e5+99;

int n,t,prt,a[N],b[N],sz[N],mark[N],ans[N];
vector<int> g[N];

void dfs1(int u,int p,int s,int &cent){
	sz[u]=1;
	for(auto v : g[u]){
		if(v==p || mark[v]) continue ;
		dfs1(v,u,s,cent);
		sz[u]+=sz[v];
	}
	if(sz[u]>=s && (cent==0 || sz[u]<sz[cent])){
		cent=u;
	}
}
void dfs2(int u,int p,int h){
	maxm(a[sz[u]],h);
	for(auto v : g[u]){
		if(v==p || mark[v]) continue ;
		dfs2(v,u,h+1);
	}
}
void solve(int rt,int m=n){
	if(m==1) return ;
	int cent=0;
	dfs1(rt,rt,(m+1)/2,cent);
	dfs1(cent,cent,0,prt);
	mark[cent]=1;
	f(i,1,sz[cent]+1) b[i]=-N;
	for(auto v : g[cent]){
		if(mark[v]) continue ;
		f(i,1,sz[v]+1) a[i]=-N;
		dfs2(v,v,1);
		f_(i,sz[v]-1,1) maxm(a[i],a[i+1]);
		f(i,1,sz[v]+1){
			maxm(ans[i],a[i]+b[i]+1);
			maxm(b[i],a[i]);
			if(i<=m-sz[v]){
				maxm(ans[i],b[i]+1);
			}
		}
	}
	for(auto v : g[cent]){
		if(mark[v]) continue ;
		solve(v,sz[v]);
	}
}
main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n;
	f(i,1,n){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}	
	solve(1);
	f(i,1,n+1){
		if(i&1) cout<<1<<'\n';
		else{
			cout<<max(1,ans[i/2])<<'\n';
		}
	}
}

Compilation message

meetings2.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   71 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 7 ms 5196 KB Output is correct
23 Correct 6 ms 5208 KB Output is correct
24 Correct 5 ms 5196 KB Output is correct
25 Correct 5 ms 5196 KB Output is correct
26 Correct 5 ms 5240 KB Output is correct
27 Correct 5 ms 5224 KB Output is correct
28 Correct 5 ms 5196 KB Output is correct
29 Correct 5 ms 5212 KB Output is correct
30 Correct 5 ms 5196 KB Output is correct
31 Correct 5 ms 5196 KB Output is correct
32 Correct 6 ms 5324 KB Output is correct
33 Correct 6 ms 5452 KB Output is correct
34 Correct 4 ms 5196 KB Output is correct
35 Correct 4 ms 5196 KB Output is correct
36 Correct 5 ms 5196 KB Output is correct
37 Correct 5 ms 5248 KB Output is correct
38 Correct 5 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 7 ms 5196 KB Output is correct
23 Correct 6 ms 5208 KB Output is correct
24 Correct 5 ms 5196 KB Output is correct
25 Correct 5 ms 5196 KB Output is correct
26 Correct 5 ms 5240 KB Output is correct
27 Correct 5 ms 5224 KB Output is correct
28 Correct 5 ms 5196 KB Output is correct
29 Correct 5 ms 5212 KB Output is correct
30 Correct 5 ms 5196 KB Output is correct
31 Correct 5 ms 5196 KB Output is correct
32 Correct 6 ms 5324 KB Output is correct
33 Correct 6 ms 5452 KB Output is correct
34 Correct 4 ms 5196 KB Output is correct
35 Correct 4 ms 5196 KB Output is correct
36 Correct 5 ms 5196 KB Output is correct
37 Correct 5 ms 5248 KB Output is correct
38 Correct 5 ms 5324 KB Output is correct
39 Correct 379 ms 14704 KB Output is correct
40 Correct 361 ms 14564 KB Output is correct
41 Correct 360 ms 14780 KB Output is correct
42 Correct 342 ms 14880 KB Output is correct
43 Correct 371 ms 14996 KB Output is correct
44 Correct 356 ms 14824 KB Output is correct
45 Correct 589 ms 20792 KB Output is correct
46 Correct 429 ms 25808 KB Output is correct
47 Correct 133 ms 14528 KB Output is correct
48 Correct 84 ms 13932 KB Output is correct
49 Correct 267 ms 15568 KB Output is correct
50 Correct 108 ms 15164 KB Output is correct
51 Correct 250 ms 24440 KB Output is correct