Submission #543266

# Submission time Handle Problem Language Result Execution time Memory
543266 2022-03-30T02:28:26 Z cheissmart Meetings 2 (JOI21_meetings2) C++14
0 / 100
3 ms 4948 KB
#include <bits/stdc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7;

void insert(map<int, int>& mp, int key, int val) {
	val = mp[key] = max(mp[key], val);
	auto it = mp.find(key);
	if(next(it) != mp.end() && next(it) -> S >= val)
		mp.erase(it);
	else {
		while(it != mp.begin() && prev(it) -> S <= val)
			mp.erase(prev(it));
	}
}

map<int, int> ans;

vi G[N];
int sz[N], n;

map<int, int> dfs(int u, int p = 0, int depth = 0) { // sz, depth
	sz[u] = 1;
	map<int, int> res;
	auto qry = [&] (map<int, int> &mp, int siz, int dep) {
		auto it = mp.lower_bound(siz);
		if(it != mp.end())
			insert(ans, min(siz, it -> F), dep + it -> S - depth * 2);
		if(it != mp.begin()) {
			it--;
			insert(ans, min(siz, it -> F), dep + it -> S - depth * 2);
		}
	};
	for(int v:G[u]) if(v != p) {
		auto tt = dfs(v, u, depth + 1);
		sz[u] += sz[v];
		qry(tt, n - sz[v], depth);
		for(auto[siz, dep]:tt) {
			qry(res, siz, dep);
		}
		for(auto[siz, dep]:tt)
			insert(res, siz, dep);
	}
	insert(res, sz[u], depth);
	return res;
}


signed main()
{
	IO_OP;
	
	cin >> n;
	ans[n / 2] = 0;
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		G[u].PB(v);
		G[v].PB(u);
	}
	dfs(1);
	
	for(int i = 1; i <= n; i++) {
		if(i & 1) cout << 1 << '\n';
		else {
			assert(ans.lower_bound(i / 2) != ans.end());
			cout << ans.lower_bound(i / 2) -> S + 1 << '\n';			
		}
	}
	
}

Compilation message

meetings2.cpp: In function 'std::map<int, int> dfs(int, int, int)':
meetings2.cpp:52:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |   for(auto[siz, dep]:tt) {
      |           ^
meetings2.cpp:55:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |   for(auto[siz, dep]:tt)
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Incorrect 2 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Incorrect 2 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Incorrect 2 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -