Submission #427318

# Submission time Handle Problem Language Result Execution time Memory
427318 2021-06-14T14:16:50 Z Osama_Alkhodairy Meetings 2 (JOI21_meetings2) C++17
100 / 100
1758 ms 28360 KB
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 200001;

int n, sz[N], blocked[N], tree[2 * N];
vector <int> v[N], ans;
vector <pair <int, int> > c;

void update(int p, int v, int d){
    p += n + 1;
    if(d == 1) tree[p] = v;
    else tree[p] = max(tree[p], v);
    for(; p > 1 ; p >>= 1){
        tree[p >> 1] = max(tree[p], tree[p ^ 1]);
    }
}
int query(int l, int r){
    r++;
    int ret = 0;
    for(l += n + 1, r += n + 1 ; l < r ; l >>= 1, r >>= 1){
        if(l & 1) ret = max(ret, tree[l++]);
        if(r & 1) ret = max(ret, tree[--r]);
    }
    return ret;
}
void dfsz(int node, int pnode){
    sz[node] = 1;
    for(auto &i : v[node]){
        if(i == pnode || blocked[i]) continue;
        dfsz(i, node);
        sz[node] += sz[i];
    }
}
int find(int node, int pnode, int n){
    for(auto &i : v[node]){
        if(i != pnode && !blocked[i] && 2 * sz[i] > n){
            return find(i, node, n);
        }
    }
    return node;
}
void dfs(int node, int pnode, int len){
    c.push_back(make_pair(sz[node], len));
    for(auto &i : v[node]){
        if(i == pnode || blocked[i]) continue;
        dfs(i, node, len + 1);
    }
}
void solve(int node){
    dfsz(node, 0);
    int cen = find(node, 0, sz[node]);
    dfsz(cen, 0);
    for(int itt = 0 ; itt < 2 ; itt++){
        vector <pair <int, int> > all;
        for(auto &i : v[cen]){
            if(blocked[i]) continue;
            c.clear();
            dfs(i, cen, 1);
            for(auto &j : c){
                int mx = query(j.first, n);
                if(mx > 0) ans[j.first] = max(ans[j.first], j.second + mx);
            }
            for(auto &j : c){
                update(j.first, j.second, 0);
                ans[min(j.first, sz[cen] - sz[i])] = max(ans[min(j.first, sz[cen] - sz[i])], j.second);
                all.push_back(j);
            }
        }
        for(auto &i : all){
            update(i.first, 0, 1);
        }
        reverse(v[cen].begin(), v[cen].end());
    }
    blocked[cen] = 1;
    for(auto &i : v[cen]){
        if(blocked[i]) continue;
        solve(i);
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0 ; i < n - 1 ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    ans.resize(n + 1);
    solve(1);
    for(int i = n ; i > 1 ; i--){
        ans[i - 1] = max(ans[i - 1], ans[i]);
    }
    for(int i = 1 ; i <= n ; i++){
        if(i % 2) cout << "1\n";
        else cout << ans[i / 2] + 1 << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 5 ms 4912 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 4 ms 5024 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 5 ms 4912 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 4 ms 5024 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Correct 15 ms 5312 KB Output is correct
23 Correct 12 ms 5288 KB Output is correct
24 Correct 14 ms 5196 KB Output is correct
25 Correct 12 ms 5196 KB Output is correct
26 Correct 11 ms 5300 KB Output is correct
27 Correct 11 ms 5196 KB Output is correct
28 Correct 14 ms 5324 KB Output is correct
29 Correct 12 ms 5196 KB Output is correct
30 Correct 12 ms 5196 KB Output is correct
31 Correct 12 ms 5196 KB Output is correct
32 Correct 16 ms 5324 KB Output is correct
33 Correct 15 ms 5452 KB Output is correct
34 Correct 7 ms 5196 KB Output is correct
35 Correct 6 ms 5296 KB Output is correct
36 Correct 16 ms 5320 KB Output is correct
37 Correct 9 ms 5324 KB Output is correct
38 Correct 12 ms 5364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 5 ms 4912 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 4 ms 5024 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Correct 15 ms 5312 KB Output is correct
23 Correct 12 ms 5288 KB Output is correct
24 Correct 14 ms 5196 KB Output is correct
25 Correct 12 ms 5196 KB Output is correct
26 Correct 11 ms 5300 KB Output is correct
27 Correct 11 ms 5196 KB Output is correct
28 Correct 14 ms 5324 KB Output is correct
29 Correct 12 ms 5196 KB Output is correct
30 Correct 12 ms 5196 KB Output is correct
31 Correct 12 ms 5196 KB Output is correct
32 Correct 16 ms 5324 KB Output is correct
33 Correct 15 ms 5452 KB Output is correct
34 Correct 7 ms 5196 KB Output is correct
35 Correct 6 ms 5296 KB Output is correct
36 Correct 16 ms 5320 KB Output is correct
37 Correct 9 ms 5324 KB Output is correct
38 Correct 12 ms 5364 KB Output is correct
39 Correct 1055 ms 17512 KB Output is correct
40 Correct 963 ms 19668 KB Output is correct
41 Correct 1127 ms 19936 KB Output is correct
42 Correct 997 ms 20124 KB Output is correct
43 Correct 984 ms 20176 KB Output is correct
44 Correct 1056 ms 20116 KB Output is correct
45 Correct 1758 ms 24464 KB Output is correct
46 Correct 1587 ms 28360 KB Output is correct
47 Correct 346 ms 19604 KB Output is correct
48 Correct 253 ms 19600 KB Output is correct
49 Correct 1051 ms 21132 KB Output is correct
50 Correct 397 ms 20640 KB Output is correct
51 Correct 1029 ms 26536 KB Output is correct