답안 #722445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722445 2023-04-12T02:31:38 Z Abrar_Al_Samit Meetings 2 (JOI21_meetings2) C++17
0 / 100
1 ms 468 KB
#include<bits/stdc++.h>
using namespace std;

const int nax = 4002;

vector<int>g[nax];
int n;
int ans[nax];
int sub[nax][nax];
int dist[nax][nax];

int dfs(int v, int r, int p = 0) {
	sub[r][v] = 1;
	if(p) dist[r][v] = dist[r][p] + 1;

	for(int u: g[v]) if(u!=p) {
		sub[r][v] += dfs(u, r, v);
	}
	return sub[r][v];
}
void PlayGround() {
	cin>>n;
	for(int i=0; i<n-1; ++i) {
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	for(int r=1; r<=n; ++r) {
		dfs(r, r);
	}
	for(int i=1; i<=n; ++i) {
		for(int j=i+1; j<=n; ++j) {
			int sz = min(sub[i][j], sub[j][i]) * 2;
			ans[sz] = max(ans[sz], dist[i][j]+1);
		}
	}


	int mx = 0;
	ans[n] = max(ans[n], 1);
	for(int i=n; i>0; --i) {
		if(i&1) ans[i] = 1;
		else {
			mx = max(mx, ans[i]);
			ans[i] = mx;
		}
	}
	for(int i=1; i<=n; ++i) {
		cout<<ans[i]<<'\n';
	}

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	PlayGround();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Halted 0 ms 0 KB -