답안 #707363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707363 2023-03-08T22:21:50 Z urosk Meetings 2 (JOI21_meetings2) C++14
100 / 100
413 ms 72496 KB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}

#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
#define maxn 200005
#define lg 23
ll n;
vector<ll> g[maxn];
vector<ll> v[maxn];
ll dub[maxn],sz[maxn];
ll st[maxn][lg];
ll in[maxn],out[maxn],ti = 0;
ll ans[maxn];
void dfs(ll u,ll p){
    st[u][0] = p;
    sz[u] = 1;
    in[u] = ++ti;
    if(u!=p) dub[u] = dub[p] + 1;
    else dub[u] = 0;
    for(ll s : g[u]){
        if(s==p) continue;
        dfs(s,u);
        sz[u]+=sz[s];
    }
    out[u] = ti-1;
}
ll get(ll u,ll p){
    for(ll s : g[u]){
        if(s==p) continue;
        if(sz[s]*2>=n) return get(s,u);
    }
    return u;
}
ll intree(ll x,ll y){return in[y]<=in[x]&&out[y]>=out[x];}
ll lca(ll x,ll y){
    if(intree(x,y)) return y;
    if(intree(y,x)) return x;
    for(ll j = lg-1;j>=0;j--){
        if(!intree(x,st[y][j])) y = st[y][j];
    }
    return st[y][0];
}
ll dis(ll x,ll y){return dub[x] + dub[y] - 2*dub[lca(x,y)];}
ll c;
void tc(){
    cin >> n;
    for(ll i = 1;i<=n-1;i++){
        ll x,y; cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1,1);
    c = get(1,1);
    dfs(c,c);
    for(ll j = 1;j<lg;j++) for(ll i = 1;i<=n;i++) st[i][j] = st[st[i][j-1]][j-1];
    for(ll i = 1;i<=n;i++) v[sz[i]].pb(i);
    ll x = c,y = c,d = 0;
    for(ll i = n/2;i>=1;i--){
        for(ll z : v[i]){
            ll dxz = dis(x,z);
            ll dyz = dis(y,z);
            if(dxz<dyz){
                swap(x,y);
                swap(dxz,dyz);
            }
            if(dxz>d){
                d = dxz;
                y = z;
            }
        }
        ans[i] = d+1;
    }
    for(ll i = 1;i<=n;i++){
        if(i&1) cout<<1<<endl;
        else cout<<ans[i/2]<<endl;
    }
}
int main(){
	daj_mi_malo_vremena
    int t; t = 1;
    while(t--){
        tc();
    }
	return 0;
}
/**
5
1 2
2 3
4 2
3 5

7
1 2
2 3
3 4
4 5
2 6
3 7
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9760 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9756 KB Output is correct
5 Correct 5 ms 9732 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9716 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9716 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9724 KB Output is correct
14 Correct 5 ms 9688 KB Output is correct
15 Correct 5 ms 9716 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9760 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9756 KB Output is correct
5 Correct 5 ms 9732 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9716 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9716 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9724 KB Output is correct
14 Correct 5 ms 9688 KB Output is correct
15 Correct 5 ms 9716 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9720 KB Output is correct
22 Correct 10 ms 10808 KB Output is correct
23 Correct 10 ms 10836 KB Output is correct
24 Correct 9 ms 10752 KB Output is correct
25 Correct 9 ms 10756 KB Output is correct
26 Correct 9 ms 10756 KB Output is correct
27 Correct 9 ms 10868 KB Output is correct
28 Correct 9 ms 10836 KB Output is correct
29 Correct 10 ms 10836 KB Output is correct
30 Correct 8 ms 10868 KB Output is correct
31 Correct 8 ms 10836 KB Output is correct
32 Correct 8 ms 10884 KB Output is correct
33 Correct 9 ms 11012 KB Output is correct
34 Correct 8 ms 10836 KB Output is correct
35 Correct 8 ms 10880 KB Output is correct
36 Correct 8 ms 10760 KB Output is correct
37 Correct 9 ms 10836 KB Output is correct
38 Correct 10 ms 10836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9760 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9756 KB Output is correct
5 Correct 5 ms 9732 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9716 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9716 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9724 KB Output is correct
14 Correct 5 ms 9688 KB Output is correct
15 Correct 5 ms 9716 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9720 KB Output is correct
22 Correct 10 ms 10808 KB Output is correct
23 Correct 10 ms 10836 KB Output is correct
24 Correct 9 ms 10752 KB Output is correct
25 Correct 9 ms 10756 KB Output is correct
26 Correct 9 ms 10756 KB Output is correct
27 Correct 9 ms 10868 KB Output is correct
28 Correct 9 ms 10836 KB Output is correct
29 Correct 10 ms 10836 KB Output is correct
30 Correct 8 ms 10868 KB Output is correct
31 Correct 8 ms 10836 KB Output is correct
32 Correct 8 ms 10884 KB Output is correct
33 Correct 9 ms 11012 KB Output is correct
34 Correct 8 ms 10836 KB Output is correct
35 Correct 8 ms 10880 KB Output is correct
36 Correct 8 ms 10760 KB Output is correct
37 Correct 9 ms 10836 KB Output is correct
38 Correct 10 ms 10836 KB Output is correct
39 Correct 328 ms 64112 KB Output is correct
40 Correct 317 ms 62780 KB Output is correct
41 Correct 303 ms 64300 KB Output is correct
42 Correct 326 ms 65216 KB Output is correct
43 Correct 317 ms 65152 KB Output is correct
44 Correct 338 ms 65304 KB Output is correct
45 Correct 413 ms 70144 KB Output is correct
46 Correct 400 ms 72496 KB Output is correct
47 Correct 266 ms 65296 KB Output is correct
48 Correct 213 ms 65308 KB Output is correct
49 Correct 317 ms 65504 KB Output is correct
50 Correct 223 ms 65156 KB Output is correct
51 Correct 379 ms 71596 KB Output is correct