Submission #543262

# Submission time Handle Problem Language Result Execution time Memory
543262 2022-03-30T02:19:10 Z cheissmart Meetings 2 (JOI21_meetings2) C++14
0 / 100
4 ms 5024 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[key, val]:tt) cerr << key << ", " << val << endl;
		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;
	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 {
			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[key, val]:tt) cerr << key << ", " << val << endl;
      |           ^
meetings2.cpp:53:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   53 |   for(auto[siz, dep]:tt) {
      |           ^
meetings2.cpp:56:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |   for(auto[siz, dep]:tt)
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Incorrect 3 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 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Incorrect 3 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 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Incorrect 3 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -