답안 #589664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589664 2022-07-05T05:46:20 Z Peti Meetings 2 (JOI21_meetings2) C++14
100 / 100
2719 ms 43704 KB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> g;
vector<int> alatt;
vector<bool> volt;

int meret(int akt, int os){
    alatt[akt] = 1;
    for(int x : g[akt])
        if(!volt[x] && x != os)
            alatt[akt] += meret(x, akt);
    return alatt[akt];
}

int getc(int akt, int os, int m){
    for(int x : g[akt])
        if(!volt[x] && x != os && alatt[x]*2 > m)
            return getc(x, akt, m);
    return akt;
}

void upd(set<pair<int, int>> &s, pair<int, int> p){
    auto it = s.insert(p).first;
    if(next(it) != s.end() && next(it)->second >= it->second){
        s.erase(it);
    }else{
        while(it != s.begin() && prev(it)->second <= it->second)
            s.erase(prev(it));
    }
}

void bejar(set<pair<int, int>> &s1, set<pair<int, int>> &s2, int akt, int t, int os, int rem){
    auto it = s1.lower_bound({alatt[akt], 0});
    if(it != s1.end()){
        //cout<<"uj: "<<2*alatt[akt]<<' '<<t<<" | "<<it->first<<' '<<it->second<<'\n';
        upd(s2, {2*alatt[akt], t + it->second + 1});
    }
    upd(s2, {min(alatt[akt], rem)*2, t+1});
    for(int x : g[akt])
        if(!volt[x] && x != os)
            bejar(s1, s2, x, t+1, akt, rem);
}

void berak(set<pair<int, int>> &s, int akt, int t, int os){
    //cout<<"berak: "<<akt<<' '<<alatt[akt]<<'\n';
    upd(s, {alatt[akt], t});
    for(int x : g[akt])
        if(!volt[x] && x != os)
            berak(s, x, t+1, akt);
}

vector<int> ki;
void decomposition(int c){
    c = getc(c, -1, meret(c, -1));
    volt[c] = true;
    meret(c, -1);

    set<pair<int, int>> s1, s2;
    for(int x : g[c]){
        if(!volt[x]){
            bejar(s1, s2, x, 1, c, alatt[c] - alatt[x]);
            berak(s1, x, 1, c);
        }
    }
    s1.clear();
    reverse(g[c].begin(), g[c].end());
    for(int x : g[c]){
        if(!volt[x]){
            bejar(s1, s2, x, 1, c, alatt[c] - alatt[x]);
            berak(s1, x, 1, c);
        }
    }

    //cout<<"centroid: "<<c<<'\n';
    for(auto p : s2){
        //cout<<p.first<<' '<<p.second<<'\n';
        ki[p.first] = max(ki[p.first], p.second);
    }

    for(int x : g[c])
        if(!volt[x])
            decomposition(x);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin>>n;

    g.resize(n);
    ki.resize(n+1);
    alatt.resize(n);
    volt.assign(n, false);
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin>>a>>b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    decomposition(0);

    /*cout<<"ki: ";
    for(int i = 0; i <= n; i++) cout<<ki[i]<<' ';
    cout<<'\n';*/

    ki[n] = max(ki[n], 1);
    for(int i = n-1; i >= 0; i--){
        ki[i] = max(ki[i], ki[i+1]);
    }

    for(int i = 1; i <= n; i++){
        cout<<(i%2 ? 1 : ki[i])<<'\n';
    }

    return 0;
}

/*
4
1 2
2 3
3 4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 15 ms 620 KB Output is correct
23 Correct 13 ms 616 KB Output is correct
24 Correct 13 ms 584 KB Output is correct
25 Correct 13 ms 588 KB Output is correct
26 Correct 12 ms 624 KB Output is correct
27 Correct 11 ms 596 KB Output is correct
28 Correct 13 ms 616 KB Output is correct
29 Correct 12 ms 628 KB Output is correct
30 Correct 14 ms 628 KB Output is correct
31 Correct 12 ms 624 KB Output is correct
32 Correct 22 ms 980 KB Output is correct
33 Correct 26 ms 1280 KB Output is correct
34 Correct 5 ms 596 KB Output is correct
35 Correct 4 ms 520 KB Output is correct
36 Correct 17 ms 676 KB Output is correct
37 Correct 5 ms 628 KB Output is correct
38 Correct 12 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 15 ms 620 KB Output is correct
23 Correct 13 ms 616 KB Output is correct
24 Correct 13 ms 584 KB Output is correct
25 Correct 13 ms 588 KB Output is correct
26 Correct 12 ms 624 KB Output is correct
27 Correct 11 ms 596 KB Output is correct
28 Correct 13 ms 616 KB Output is correct
29 Correct 12 ms 628 KB Output is correct
30 Correct 14 ms 628 KB Output is correct
31 Correct 12 ms 624 KB Output is correct
32 Correct 22 ms 980 KB Output is correct
33 Correct 26 ms 1280 KB Output is correct
34 Correct 5 ms 596 KB Output is correct
35 Correct 4 ms 520 KB Output is correct
36 Correct 17 ms 676 KB Output is correct
37 Correct 5 ms 628 KB Output is correct
38 Correct 12 ms 980 KB Output is correct
39 Correct 1178 ms 15732 KB Output is correct
40 Correct 1284 ms 15404 KB Output is correct
41 Correct 1244 ms 15748 KB Output is correct
42 Correct 1146 ms 16012 KB Output is correct
43 Correct 1262 ms 16016 KB Output is correct
44 Correct 1255 ms 16016 KB Output is correct
45 Correct 2719 ms 32704 KB Output is correct
46 Correct 2461 ms 43704 KB Output is correct
47 Correct 259 ms 16364 KB Output is correct
48 Correct 135 ms 16436 KB Output is correct
49 Correct 1358 ms 17168 KB Output is correct
50 Correct 236 ms 16608 KB Output is correct
51 Correct 1264 ms 37932 KB Output is correct