Submission #836386

# Submission time Handle Problem Language Result Execution time Memory
836386 2023-08-24T10:47:29 Z sunwukong123 Meetings 2 (JOI21_meetings2) C++14
100 / 100
541 ms 137616 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int MAXN = 400005;
const int inf=1000000500ll;
const int oo =1000000000000000000ll;
const int MOD = (int)1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi;
int n;
vector<pi> adj[MAXN];
/*
this is essentially finding diameter while updating some edges from weight 1 to weight 0
when should you update an edge from weight 1 to weight 0?
at t=min(sz[a],sz[b])
so just use the dynamicdiameter code to solve this as well
note that you can probably simplify many things, because we are always removing the leaf, and the edges are unweighted.
*/
int sz[MAXN];
vector<int> T[MAXN];
int id[MAXN];
int TIME;
int in[MAXN];
int out[MAXN];
struct node {
	int s,e,m;
	int a,b,c,ab,bc,abc;
	int lazy;
	node *l, *r;
	node(int _s, int _e){
		s=_s;e=_e;m=(s+e)/2;
		a=b=c=ab=bc=abc=lazy=0;
		if(s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	void value(){
		if(lazy==0)return;
		a+=lazy;
		b-=2*lazy;
		c+=lazy;
		ab-=lazy;
		bc-=lazy;
		if(s!=e){
			l->lazy+=lazy;
			r->lazy+=lazy;
		}
		lazy=0;
	}
	void update(int x, int y, int nval){
		value();
		if(s==x&&e==y){
			lazy+=nval;
			return;
		}
		if(x>m)r->update(x,y,nval);
		else if(y<=m)l->update(x,y,nval);
		else {
			l->update(x,m,nval);
			r->update(m+1,y,nval);
		}

		l->value();r->value();
		a=max(l->a,r->a);
		b=max(l->b,r->b);
		c=max(l->c,r->c);
		ab=max({l->ab,r->ab,l->a+r->b});
		bc=max({l->bc,r->bc,l->b+r->c});
		abc=max({l->abc,r->abc,l->a+r->bc,l->ab+r->c});
		
	}
}*seg=new node(0,MAXN);
void dfs(int x, int p){
	in[x]=TIME++;
	sz[x]=1;
	for(auto v:adj[x])if(v.first!=p){
		dfs(v.first,x);
		sz[x]+=sz[v.first];
		id[v.second]=v.first;
		out[x]=TIME++;
	}
	if(out[x]==0)out[x]=in[x];

	int ti=min(sz[x],n-sz[x]);
	T[ti].push_back(x);
}
int32_t main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=1;i<=n-1;i++){
		int a,b; cin >> a >> b;
		adj[a].push_back({b,i});
		adj[b].push_back({a,i});
	}

	dfs(1,-1);


	for(int i=1;i<=n-1;i++){
		seg->update(in[id[i]],out[id[i]],1);
	}

	for(int i=1;i<=n/2;i++){
		cout<<"1\n";
		cout<<1+seg->abc<<'\n';
		for(auto x:T[i]){

			seg->update(in[x],out[x],-1);
		}
	}
	if(n%2==1)cout<<"1\n";
}

# Verdict Execution time Memory Grader output
1 Correct 54 ms 106704 KB Output is correct
2 Correct 61 ms 106784 KB Output is correct
3 Correct 50 ms 106708 KB Output is correct
4 Correct 55 ms 106728 KB Output is correct
5 Correct 51 ms 106772 KB Output is correct
6 Correct 48 ms 106744 KB Output is correct
7 Correct 49 ms 106700 KB Output is correct
8 Correct 57 ms 106700 KB Output is correct
9 Correct 50 ms 106780 KB Output is correct
10 Correct 51 ms 106700 KB Output is correct
11 Correct 54 ms 106700 KB Output is correct
12 Correct 49 ms 106704 KB Output is correct
13 Correct 50 ms 106700 KB Output is correct
14 Correct 52 ms 106704 KB Output is correct
15 Correct 48 ms 106704 KB Output is correct
16 Correct 49 ms 106760 KB Output is correct
17 Correct 51 ms 106720 KB Output is correct
18 Correct 48 ms 106772 KB Output is correct
19 Correct 53 ms 106796 KB Output is correct
20 Correct 64 ms 106768 KB Output is correct
21 Correct 47 ms 106700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 106704 KB Output is correct
2 Correct 61 ms 106784 KB Output is correct
3 Correct 50 ms 106708 KB Output is correct
4 Correct 55 ms 106728 KB Output is correct
5 Correct 51 ms 106772 KB Output is correct
6 Correct 48 ms 106744 KB Output is correct
7 Correct 49 ms 106700 KB Output is correct
8 Correct 57 ms 106700 KB Output is correct
9 Correct 50 ms 106780 KB Output is correct
10 Correct 51 ms 106700 KB Output is correct
11 Correct 54 ms 106700 KB Output is correct
12 Correct 49 ms 106704 KB Output is correct
13 Correct 50 ms 106700 KB Output is correct
14 Correct 52 ms 106704 KB Output is correct
15 Correct 48 ms 106704 KB Output is correct
16 Correct 49 ms 106760 KB Output is correct
17 Correct 51 ms 106720 KB Output is correct
18 Correct 48 ms 106772 KB Output is correct
19 Correct 53 ms 106796 KB Output is correct
20 Correct 64 ms 106768 KB Output is correct
21 Correct 47 ms 106700 KB Output is correct
22 Correct 50 ms 107240 KB Output is correct
23 Correct 50 ms 107212 KB Output is correct
24 Correct 52 ms 107228 KB Output is correct
25 Correct 53 ms 107196 KB Output is correct
26 Correct 58 ms 107196 KB Output is correct
27 Correct 62 ms 107140 KB Output is correct
28 Correct 57 ms 107212 KB Output is correct
29 Correct 55 ms 107208 KB Output is correct
30 Correct 56 ms 107212 KB Output is correct
31 Correct 56 ms 107132 KB Output is correct
32 Correct 60 ms 107376 KB Output is correct
33 Correct 58 ms 107432 KB Output is correct
34 Correct 56 ms 107224 KB Output is correct
35 Correct 55 ms 107212 KB Output is correct
36 Correct 65 ms 107192 KB Output is correct
37 Correct 55 ms 107084 KB Output is correct
38 Correct 55 ms 107212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 106704 KB Output is correct
2 Correct 61 ms 106784 KB Output is correct
3 Correct 50 ms 106708 KB Output is correct
4 Correct 55 ms 106728 KB Output is correct
5 Correct 51 ms 106772 KB Output is correct
6 Correct 48 ms 106744 KB Output is correct
7 Correct 49 ms 106700 KB Output is correct
8 Correct 57 ms 106700 KB Output is correct
9 Correct 50 ms 106780 KB Output is correct
10 Correct 51 ms 106700 KB Output is correct
11 Correct 54 ms 106700 KB Output is correct
12 Correct 49 ms 106704 KB Output is correct
13 Correct 50 ms 106700 KB Output is correct
14 Correct 52 ms 106704 KB Output is correct
15 Correct 48 ms 106704 KB Output is correct
16 Correct 49 ms 106760 KB Output is correct
17 Correct 51 ms 106720 KB Output is correct
18 Correct 48 ms 106772 KB Output is correct
19 Correct 53 ms 106796 KB Output is correct
20 Correct 64 ms 106768 KB Output is correct
21 Correct 47 ms 106700 KB Output is correct
22 Correct 50 ms 107240 KB Output is correct
23 Correct 50 ms 107212 KB Output is correct
24 Correct 52 ms 107228 KB Output is correct
25 Correct 53 ms 107196 KB Output is correct
26 Correct 58 ms 107196 KB Output is correct
27 Correct 62 ms 107140 KB Output is correct
28 Correct 57 ms 107212 KB Output is correct
29 Correct 55 ms 107208 KB Output is correct
30 Correct 56 ms 107212 KB Output is correct
31 Correct 56 ms 107132 KB Output is correct
32 Correct 60 ms 107376 KB Output is correct
33 Correct 58 ms 107432 KB Output is correct
34 Correct 56 ms 107224 KB Output is correct
35 Correct 55 ms 107212 KB Output is correct
36 Correct 65 ms 107192 KB Output is correct
37 Correct 55 ms 107084 KB Output is correct
38 Correct 55 ms 107212 KB Output is correct
39 Correct 536 ms 125424 KB Output is correct
40 Correct 502 ms 124700 KB Output is correct
41 Correct 537 ms 125568 KB Output is correct
42 Correct 541 ms 125688 KB Output is correct
43 Correct 535 ms 125712 KB Output is correct
44 Correct 535 ms 125884 KB Output is correct
45 Correct 449 ms 132260 KB Output is correct
46 Correct 408 ms 137616 KB Output is correct
47 Correct 344 ms 128824 KB Output is correct
48 Correct 220 ms 128920 KB Output is correct
49 Correct 326 ms 128244 KB Output is correct
50 Correct 221 ms 127540 KB Output is correct
51 Correct 295 ms 135448 KB Output is correct