Submission #1042077

# Submission time Handle Problem Language Result Execution time Memory
1042077 2024-08-02T14:09:00 Z pcc Meetings 2 (JOI21_meetings2) C++17
0 / 100
2 ms 15964 KB
#include <bits/stdc++.h>
using namespace std;


const int mxn = 4e5+10;
vector<int> tree[mxn];
bitset<mxn> del;
int sz[mxn],dep[mxn];
int N;
int ans[mxn];

struct BIT{
	int bit[mxn];
	int s;
	void resize(int n){
		s = n;
		fill(bit,bit+s+1,-mxn);
	}
	void modify(int p,int v){
		p = s-p;
		assert(p>0);
		for(;p<s;p+=p&-p)bit[p] = max(bit[p],v);
	}
	int getval(int p){
		p = s-p;
		int re = -mxn;
		for(;p>0;p-= p&-p)re = max(re,bit[p]);
		return re;
	}
};

BIT bit;

void szdfs(int now,int par){
	sz[now] = 1;
	for(auto nxt:tree[now]){
		if(nxt == par||del[nxt])continue;
		szdfs(nxt,now);
		sz[now] += sz[nxt];
	}
	return;
}
int find_centroid(int now,int par,int tar){
	for(auto nxt:tree[now]){
		if(nxt == par||del[nxt])continue;
		if(sz[nxt]>tar)return find_centroid(nxt,now,tar);
	}
	return now;
}

void dfs(int now,int par,int psz){
	if(now == par)dep[now] = 1;
	for(auto nxt:tree[now]){
		if(nxt == par||del[nxt])continue;
		dep[nxt] = dep[now]+1;
		dfs(nxt,now,psz);
	}
	int pos = sz[now];
	ans[pos*2] = max(ans[pos*2],dep[now]+bit.getval(pos)+1);
	ans[min(psz,pos)*2] = max(ans[min(psz,pos)*2],dep[now]+1);
	return;
}
void dfs2(int now,int par){
	bit.modify(sz[now],dep[now]);
	for(auto nxt:tree[now]){
		if(nxt == par||del[nxt])continue;
		dfs2(nxt,now);
	}
	return;
}

void cd(int now,int par){
	dep[now] = 0;
	szdfs(now,now);
	bit.resize(sz[now]+3);
	now = find_centroid(now,now,(sz[now]-1)>>1);
	szdfs(now,now);
	del[now] = true;
	for(auto nxt:tree[now]){
		if(del[nxt])continue;
		dep[nxt] = 1;
		dfs(nxt,nxt,N-sz[nxt]);
		dfs2(nxt,nxt);
	}
	for(auto nxt:tree[now]){
		if(!del[nxt])cd(nxt,now);
	}
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N;
	fill(ans,ans+N+1,1);
	for(int i = 1;i<N;i++){
		int a,b;
		cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	cd(1,1);
	for(int i = N;i>=1;i--)ans[i] = max(ans[i],ans[i+1]);
	for(int i = 1;i<=N;i+=2)ans[i] = 1;
	for(int i = 1;i<=N;i++)cout<<ans[i]<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 15964 KB Output is correct
2 Correct 2 ms 15964 KB Output is correct
3 Correct 2 ms 15964 KB Output is correct
4 Correct 2 ms 15964 KB Output is correct
5 Correct 2 ms 15964 KB Output is correct
6 Incorrect 2 ms 15964 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 15964 KB Output is correct
2 Correct 2 ms 15964 KB Output is correct
3 Correct 2 ms 15964 KB Output is correct
4 Correct 2 ms 15964 KB Output is correct
5 Correct 2 ms 15964 KB Output is correct
6 Incorrect 2 ms 15964 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 15964 KB Output is correct
2 Correct 2 ms 15964 KB Output is correct
3 Correct 2 ms 15964 KB Output is correct
4 Correct 2 ms 15964 KB Output is correct
5 Correct 2 ms 15964 KB Output is correct
6 Incorrect 2 ms 15964 KB Output isn't correct
7 Halted 0 ms 0 KB -