Submission #532871

# Submission time Handle Problem Language Result Execution time Memory
532871 2022-03-04T06:55:50 Z Koosha_mv Meetings 2 (JOI21_meetings2) C++14
0 / 100
4 ms 5068 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 || m<n) 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]);
		//cout<<v<<" : "<<endl;
		//dbga(a,1,sz[v]+1);
		f(i,1,sz[v]+1){
			maxm(ans[i],a[i]+b[i]+1);
			maxm(b[i],a[i]);
			//cout<<i<<" -> "<<sz[v]<<endl;
			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:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 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 5068 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 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 4932 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 5028 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Incorrect 3 ms 4940 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 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 5068 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 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 4932 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 5028 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Incorrect 3 ms 4940 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 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 5068 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 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 4932 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 5028 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Incorrect 3 ms 4940 KB Output isn't correct
22 Halted 0 ms 0 KB -