Submission #523303

# Submission time Handle Problem Language Result Execution time Memory
523303 2022-02-07T11:00:04 Z amunduzbaev Meetings 2 (JOI21_meetings2) C++17
20 / 100
4000 ms 234112 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
 
const int N = 2e5 + 5;
vector<int> edges[N], S[N];
int used[N], ss[N], rr[N];
int sub[N], n, d[N];
 
void dff(int u, int p = -1){
	ss[u] = 1;
	for(auto x : edges[u]){
		if(x == p) continue;
		dff(x, u);
		ss[u] += ss[x];
	}
}
 
void dfs(int u, int& C, int n, int p = -1){
	sub[u] = 1;
	if(p == -1) d[u] = 0;
	for(auto x : edges[u]){
		if(x == p) continue;
		if(!used[x]){
			d[x] = d[u] + 1;
			dfs(x, C, n, u);
			sub[u] += sub[x];
		} else {
			if(ss[u] > ss[x]) sub[u] += ss[x];
			else sub[u] += (::n - ss[u]);
		}
	}
	if(sub[u] > n / 2 && C == -1) C = u;
}
 
void get(int u, vector<int>& tt, int p = -1){
	tt.push_back(u);
	for(auto x : edges[u]){
		if(used[x] || x == p) continue;
		get(x, tt, u);
	}
}
 
void dec(int u, int n){
	int C = -1;
	dfs(u, C, n), dfs(C, C, n);
	set<ar<int, 2>> ss;
	
	auto add = [&](ar<int, 2> x){
		auto it = ss.lower_bound({x[0] + 1, -1});
		if(it != ss.end()){
			if((*it)[1] >= x[1]) return;;
		}
		
		vector<ar<int, 2>> del;
		while(it != ss.begin()){
			it--;
			if((*it)[1] <= x[1]) del.push_back(*it);
			else break;
		}
		
		for(auto v : del) ss.erase(v);
		ss.insert(x);
	};
	
	for(auto v : edges[C]){
		if(used[v]) continue;
		S[v].clear(); get(v, S[v], C);
		for(auto x : S[v]){
			auto it = ss.lower_bound({sub[x], -1});
			if(it != ss.end()){
				rr[sub[x]] = max(rr[sub[x]], d[x] + (*it)[1] + 1);
			}
		} for(auto x : S[v]) add({sub[x], d[x]});
	}
	
	reverse(edges[C].begin(), edges[C].end());
	ss.clear();
	for(auto v : edges[C]){
		if(used[v]) continue;
		for(auto x : S[v]){
			auto it = ss.lower_bound({sub[x], -1});
			if(it != ss.end()){
				rr[sub[x]] = max(rr[sub[x]], d[x] + (*it)[1] + 1);
			}
			
			rr[min(sub[x], n - (int)S[v].size())] = 
			max(rr[min(sub[x], n - (int)S[v].size())], d[x] + 1);
		} for(auto x : S[v]) add({sub[x], d[x]});
	}
	
	used[C] = 1;
	for(auto x : edges[C]){
		if(used[x]) continue;
		//~ tt.clear(); get(x, C);
		dec(x, (int)S[x].size());
	}
}
 
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin>>n;
	for(int i=1;i<n;i++){
		int a, b; cin>>a>>b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	
	dff(1);
	dec(1, n);
	rr[n] = 1;
	for(int i=n;i>0;i--) rr[i] = max(rr[i], rr[i+1]);
	for(int i=1;i<=n;i++){
		if(i&1) cout<<1<<"\n";
		else cout<<rr[i/2]<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 5 ms 9732 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 7 ms 9732 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 5 ms 9676 KB Output is correct
7 Correct 5 ms 9676 KB Output is correct
8 Correct 7 ms 9672 KB Output is correct
9 Correct 6 ms 9676 KB Output is correct
10 Correct 5 ms 9696 KB Output is correct
11 Correct 5 ms 9740 KB Output is correct
12 Correct 5 ms 9676 KB Output is correct
13 Correct 5 ms 9676 KB Output is correct
14 Correct 5 ms 9676 KB Output is correct
15 Correct 5 ms 9676 KB Output is correct
16 Correct 5 ms 9676 KB Output is correct
17 Correct 5 ms 9676 KB Output is correct
18 Correct 5 ms 9676 KB Output is correct
19 Correct 5 ms 9676 KB Output is correct
20 Correct 5 ms 9676 KB Output is correct
21 Correct 5 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 5 ms 9732 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 7 ms 9732 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 5 ms 9676 KB Output is correct
7 Correct 5 ms 9676 KB Output is correct
8 Correct 7 ms 9672 KB Output is correct
9 Correct 6 ms 9676 KB Output is correct
10 Correct 5 ms 9696 KB Output is correct
11 Correct 5 ms 9740 KB Output is correct
12 Correct 5 ms 9676 KB Output is correct
13 Correct 5 ms 9676 KB Output is correct
14 Correct 5 ms 9676 KB Output is correct
15 Correct 5 ms 9676 KB Output is correct
16 Correct 5 ms 9676 KB Output is correct
17 Correct 5 ms 9676 KB Output is correct
18 Correct 5 ms 9676 KB Output is correct
19 Correct 5 ms 9676 KB Output is correct
20 Correct 5 ms 9676 KB Output is correct
21 Correct 5 ms 9676 KB Output is correct
22 Correct 11 ms 10060 KB Output is correct
23 Correct 12 ms 10036 KB Output is correct
24 Correct 11 ms 10060 KB Output is correct
25 Correct 11 ms 10060 KB Output is correct
26 Correct 12 ms 10112 KB Output is correct
27 Correct 12 ms 10036 KB Output is correct
28 Correct 11 ms 10132 KB Output is correct
29 Correct 11 ms 10060 KB Output is correct
30 Correct 14 ms 10060 KB Output is correct
31 Correct 15 ms 10060 KB Output is correct
32 Correct 198 ms 21372 KB Output is correct
33 Correct 469 ms 39900 KB Output is correct
34 Correct 7 ms 10060 KB Output is correct
35 Correct 8 ms 10060 KB Output is correct
36 Correct 31 ms 10496 KB Output is correct
37 Correct 12 ms 10084 KB Output is correct
38 Correct 118 ms 17596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 5 ms 9732 KB Output is correct
3 Correct 5 ms 9676 KB Output is correct
4 Correct 7 ms 9732 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 5 ms 9676 KB Output is correct
7 Correct 5 ms 9676 KB Output is correct
8 Correct 7 ms 9672 KB Output is correct
9 Correct 6 ms 9676 KB Output is correct
10 Correct 5 ms 9696 KB Output is correct
11 Correct 5 ms 9740 KB Output is correct
12 Correct 5 ms 9676 KB Output is correct
13 Correct 5 ms 9676 KB Output is correct
14 Correct 5 ms 9676 KB Output is correct
15 Correct 5 ms 9676 KB Output is correct
16 Correct 5 ms 9676 KB Output is correct
17 Correct 5 ms 9676 KB Output is correct
18 Correct 5 ms 9676 KB Output is correct
19 Correct 5 ms 9676 KB Output is correct
20 Correct 5 ms 9676 KB Output is correct
21 Correct 5 ms 9676 KB Output is correct
22 Correct 11 ms 10060 KB Output is correct
23 Correct 12 ms 10036 KB Output is correct
24 Correct 11 ms 10060 KB Output is correct
25 Correct 11 ms 10060 KB Output is correct
26 Correct 12 ms 10112 KB Output is correct
27 Correct 12 ms 10036 KB Output is correct
28 Correct 11 ms 10132 KB Output is correct
29 Correct 11 ms 10060 KB Output is correct
30 Correct 14 ms 10060 KB Output is correct
31 Correct 15 ms 10060 KB Output is correct
32 Correct 198 ms 21372 KB Output is correct
33 Correct 469 ms 39900 KB Output is correct
34 Correct 7 ms 10060 KB Output is correct
35 Correct 8 ms 10060 KB Output is correct
36 Correct 31 ms 10496 KB Output is correct
37 Correct 12 ms 10084 KB Output is correct
38 Correct 118 ms 17596 KB Output is correct
39 Correct 721 ms 31540 KB Output is correct
40 Correct 703 ms 31044 KB Output is correct
41 Correct 664 ms 31432 KB Output is correct
42 Correct 676 ms 31648 KB Output is correct
43 Correct 723 ms 31788 KB Output is correct
44 Correct 666 ms 31928 KB Output is correct
45 Execution timed out 4078 ms 234112 KB Time limit exceeded
46 Halted 0 ms 0 KB -