답안 #976539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976539 2024-05-06T16:46:27 Z happy_node Meetings 2 (JOI21_meetings2) C++17
0 / 100
5 ms 6492 KB
#include <bits/stdc++.h>
using namespace std;

const int MX=2e5+5;
int N;
vector<int> adj[MX];

int sz[MX], ans[MX];

void dfs(int v, int p, int head, int dep) {
	sz[v]=1;
	for(auto u:adj[v]) {
		if(u==p) continue;
		dfs(u,v,head,dep+1);
		sz[v]+=sz[u];
	}
}	

void dfs2(int v, int p, int head, int dep) {
	for(auto u:adj[v]) {
		if(u==p) continue;
		dfs2(u,v,head,dep+1);
	}
	int k=min(sz[v],N-sz[head]);
	ans[2*k]=max(ans[2*k],dep+1);
}	


int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	cin>>N;
	for(int i=1;i<N;i++) {
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for(int r=1;r<=N;r++) {
		for(auto u:adj[r]) {
			dfs(u,r,u,1);
			dfs2(u,r,u,1);
		}
	}

	for(int i=2*N;i>=1;i--) ans[i]=max(ans[i],ans[i+1]);

	for(int i=1;i<=N;i++) {
		if(i&1) cout<<1<<'\n';
		else cout<<ans[i]<<'\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 5 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Incorrect 2 ms 6492 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 5 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Incorrect 2 ms 6492 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 5 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Incorrect 2 ms 6492 KB Output isn't correct
6 Halted 0 ms 0 KB -