Submission #722439

# Submission time Handle Problem Language Result Execution time Memory
722439 2023-04-12T02:00:09 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];

int dfs0(int v, int p = 0) {
	sub[v] = 1;
	for(int u: g[v]) if(u!=p) {
		sub[v] += dfs0(u, v);
	}
	return sub[v];
}
void dfs(int v, int p = 0, int d = 1, int ot = n) {
	if(p) ans[min(sub[v], ot) * 2] = max(ans[min(sub[v], ot) * 2], d);

	for(int u : g[v]) if(u!=p) {
		int new_ot = ot;
		if(p==0) {
			new_ot = ot - sub[u];
		}
		dfs(u, v, d+1, new_ot);
	}
}
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) {
		dfs0(r);
		dfs(r);
	}

	int mx = 0;
	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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 416 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 416 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 416 KB Output isn't correct
6 Halted 0 ms 0 KB -