Submission #869296

# Submission time Handle Problem Language Result Execution time Memory
869296 2023-11-04T01:35:37 Z NK_ Meetings 2 (JOI21_meetings2) C++17
100 / 100
281 ms 63824 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front
 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
 
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
 
using db = long double;
 
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
 
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;

struct T {
	int a, b, c, ab, bc, abc;
	T() { a = b = c = ab = bc = abc = -MOD; }
	T(int x) {
		a = x, b = -2*x, c = x;
		ab = -x, bc = -x;
		abc = 0;
	}
};

struct Seg {
	const T ID = T(); T comb(T a, T b) {
		T r = T(); 

		r.a = max(a.a, b.a), r.b = max(a.b, b.b), r.c = max(a.c, b.c);
		r.ab = max({a.ab, b.ab, a.a + b.b}), r.bc = max({a.bc, b.bc, a.b + b.c});
		r.abc = max({a.abc, b.abc, a.ab + b.c, a.a + b.bc});

		return r;
	};

	V<T> seg; int n;
	void init(int _n) {
		n = 1; while(n < _n) n *= 2;
		seg.assign(2*n, ID);
	}

	void pull(int x) { seg[x] = comb(seg[2*x], seg[2*x+1]); }

	void upd(int p, T x) {
		seg[p += n] = x; for(p /= 2; p; p /= 2) pull(p);
	}

	T get() { return seg[1]; };
};


int main() {
	cin.tie(0)->sync_with_stdio(0);

	int N; cin >> N;

	V<vi> adj(N); 
	for(int i = 0; i < N-1; i++) {
		int u, v; cin >> u >> v; --u, --v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	vi sub(N), dep(N), X(N, MOD); int TIME = 0;
	V<vi> pos(N);
	function<void(int, int)> prep = [&](int u, int p) {
		sub[u] = 1; dep[u] = (p == -1 ? 0 : dep[p] + 1); pos[u].pb(TIME++);
		for(auto& v : adj[u]) if (v != p) {
			prep(v, u);
			X[u] = min(X[u], N - sub[v]);
			sub[u] += sub[v];
			pos[u].pb(TIME++);
		}

		X[u] = min(X[u], sub[u]);
	};

	prep(0, -1);

	vi U(N); iota(begin(U), end(U), 0);
	sort(begin(U), end(U), [&](int a, int b) {
		return X[a] > X[b];
	});	

	vi ans(N, 1); 
	Seg st; st.init(TIME);
	for(int i = N / 2, cur = 0; i >= 1; i--) {
		while(cur < N && X[U[cur]] >= i) {
			int x = U[cur];
			for(auto t : pos[x]) {
				st.upd(t, T(dep[x]));
			}
			cur++;
		}
		ans[2 * i - 1] = st.get().abc + 1;
	}	

	for(int i = 0; i < N; i++) cout << ans[i] << nl;


	exit(0-0);
} 	 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 3 ms 1388 KB Output is correct
23 Correct 3 ms 1372 KB Output is correct
24 Correct 3 ms 1372 KB Output is correct
25 Correct 3 ms 1372 KB Output is correct
26 Correct 3 ms 1372 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 3 ms 1368 KB Output is correct
29 Correct 3 ms 1368 KB Output is correct
30 Correct 3 ms 1368 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 3 ms 1372 KB Output is correct
33 Correct 3 ms 1628 KB Output is correct
34 Correct 3 ms 1372 KB Output is correct
35 Correct 2 ms 1372 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 2 ms 1372 KB Output is correct
38 Correct 3 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 3 ms 1388 KB Output is correct
23 Correct 3 ms 1372 KB Output is correct
24 Correct 3 ms 1372 KB Output is correct
25 Correct 3 ms 1372 KB Output is correct
26 Correct 3 ms 1372 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 3 ms 1368 KB Output is correct
29 Correct 3 ms 1368 KB Output is correct
30 Correct 3 ms 1368 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 3 ms 1372 KB Output is correct
33 Correct 3 ms 1628 KB Output is correct
34 Correct 3 ms 1372 KB Output is correct
35 Correct 2 ms 1372 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 2 ms 1372 KB Output is correct
38 Correct 3 ms 1372 KB Output is correct
39 Correct 244 ms 51024 KB Output is correct
40 Correct 241 ms 50492 KB Output is correct
41 Correct 246 ms 51232 KB Output is correct
42 Correct 261 ms 51540 KB Output is correct
43 Correct 237 ms 51540 KB Output is correct
44 Correct 281 ms 51668 KB Output is correct
45 Correct 241 ms 58292 KB Output is correct
46 Correct 226 ms 63824 KB Output is correct
47 Correct 208 ms 52168 KB Output is correct
48 Correct 179 ms 52676 KB Output is correct
49 Correct 187 ms 52808 KB Output is correct
50 Correct 182 ms 52936 KB Output is correct
51 Correct 188 ms 62872 KB Output is correct