Submission #602020

# Submission time Handle Problem Language Result Execution time Memory
602020 2022-07-22T13:46:48 Z jamezzz Meetings 2 (JOI21_meetings2) C++17
20 / 100
5 ms 2388 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007

inline int add(int a,int b){
	int r=a+b;
	while(r>=mod)r-=mod;
	while(r<0)r+=mod;
	return r;
}

inline int mult(int a,int b){
	return (int)(((ll)(a*b))%mod);
}

inline int rd(){
	int x=0;
	char ch=getchar_unlocked();
	while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
    while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
		x=(x<<3)+(x<<1)+(ch&15);
		ch=getchar_unlocked();
	}
	return x;
}

#define maxn 20005

int n,par[maxn][20],d[maxn],sub[maxn],ans[maxn];
vector<int> AL[maxn],stuff[maxn];

void dfs(int u){
	sub[u]=1;
	for(int v:AL[u]){
		if(par[u][0]==v)continue;
		par[v][0]=u;
		d[v]=d[u]+1;
		dfs(v);
		sub[u]+=sub[v];
	}
}

int lca(int a,int b){
	if(d[a]<d[b])swap(a,b);
	for(int k=19;k>=0;--k){
		if(par[a][k]!=0&&d[par[a][k]]>=d[b])a=par[a][k];
	}
	if(a==b)return a;
	for(int k=19;k>=0;--k){
		if(par[a][k]!=par[b][k])a=par[a][k],b=par[b][k];
	}
	return par[a][0];
}

int dist(int a,int b){
	return d[a]+d[b]-2*d[lca(a,b)];
}

int main(){
	sf("%d",&n);
	for(int i=0;i<n-1;++i){
		int a,b;sf("%d%d",&a,&b);
		AL[a].pb(b);AL[b].pb(a);
	}
	
	dfs(1);
	int rt=0;
	for(int u=1;u<=n;++u){
		bool can=true;
		if(n-sub[u]>n/2)can=false;
		for(int v:AL[u]){
			if(v==par[u][0])continue;
			if(sub[v]>n/2)can=false;
		}
		if(can)rt=u;
	}
	d[rt]=0;par[rt][0]=0;
	dfs(rt);
	for(int k=1;k<20;++k){
		for(int i=1;i<=n;++i){
			if(par[i][k-1]==0)par[i][k]=0;;
			par[i][k]=par[par[i][k-1]][k-1];
		}
	}
	
	for(int i=1;i<=n;++i)stuff[sub[i]].pb(i);
	int a=rt,b=rt,mx=0;
	for(int i=n/2;i>=1;--i){
		for(int x:stuff[i]){
			int d1=dist(a,x),d2=dist(b,x);
			if(d1>=d2&&d1>mx)b=x,mx=d1;
			else if(d2>=d1&&d2>mx)a=x,mx=d2;
		}
		ans[i]=mx+1;
	}
	
	for(int i=1;i<=n;++i){
		if(i%2)pf("1\n");
		else pf("%d\n",ans[i/2]);
	}
}

Compilation message

meetings2.cpp: In function 'int main()':
meetings2.cpp:90:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |  sf("%d",&n);
      |    ^
meetings2.cpp:92:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   int a,b;sf("%d%d",&a,&b);
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1252 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1256 KB Output is correct
8 Correct 1 ms 1252 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1248 KB Output is correct
14 Correct 1 ms 1252 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1252 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1256 KB Output is correct
8 Correct 1 ms 1252 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1248 KB Output is correct
14 Correct 1 ms 1252 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 3 ms 1776 KB Output is correct
23 Correct 3 ms 1776 KB Output is correct
24 Correct 4 ms 1776 KB Output is correct
25 Correct 4 ms 1772 KB Output is correct
26 Correct 3 ms 1748 KB Output is correct
27 Correct 4 ms 1772 KB Output is correct
28 Correct 4 ms 1772 KB Output is correct
29 Correct 4 ms 1748 KB Output is correct
30 Correct 4 ms 1748 KB Output is correct
31 Correct 5 ms 1748 KB Output is correct
32 Correct 4 ms 1876 KB Output is correct
33 Correct 5 ms 1964 KB Output is correct
34 Correct 3 ms 1720 KB Output is correct
35 Correct 3 ms 1772 KB Output is correct
36 Correct 4 ms 1820 KB Output is correct
37 Correct 3 ms 1748 KB Output is correct
38 Correct 4 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1252 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1256 KB Output is correct
8 Correct 1 ms 1252 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1248 KB Output is correct
14 Correct 1 ms 1252 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 3 ms 1776 KB Output is correct
23 Correct 3 ms 1776 KB Output is correct
24 Correct 4 ms 1776 KB Output is correct
25 Correct 4 ms 1772 KB Output is correct
26 Correct 3 ms 1748 KB Output is correct
27 Correct 4 ms 1772 KB Output is correct
28 Correct 4 ms 1772 KB Output is correct
29 Correct 4 ms 1748 KB Output is correct
30 Correct 4 ms 1748 KB Output is correct
31 Correct 5 ms 1748 KB Output is correct
32 Correct 4 ms 1876 KB Output is correct
33 Correct 5 ms 1964 KB Output is correct
34 Correct 3 ms 1720 KB Output is correct
35 Correct 3 ms 1772 KB Output is correct
36 Correct 4 ms 1820 KB Output is correct
37 Correct 3 ms 1748 KB Output is correct
38 Correct 4 ms 1876 KB Output is correct
39 Runtime error 2 ms 2388 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -