Submission #397927

# Submission time Handle Problem Language Result Execution time Memory
397927 2021-05-03T11:47:32 Z Jarif_Rahman Meetings 2 (JOI21_meetings2) C++17
20 / 100
4000 ms 53676 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

int n;

vector<vector<int>> v;
vector<int> ans;
vector<set<pair<int, int>>> s;
vector<int> sz;
vector<multiset<int>> ms;

void dfs_sz(int nd, int ss){
    for(int x: v[nd]) if(x != ss) dfs_sz(x, nd);
    for(int x: v[nd]) if(x != ss) sz[nd]+=sz[x];
}

void dfs(int nd, int ss, int dis, bool keep){
    int mx = 0, in = -1;
    for(int x: v[nd]) if(x != ss && sz[x] > mx) mx = sz[x], in = x;
    for(int x: v[nd]) if(x != ss && x != in) dfs(x, nd, dis+1, 0);
    if(in != -1){
        dfs(in, nd, dis+1, 1);
        swap(s[nd], s[in]);
        for(auto [szz0, d0]: s[nd]){
            int szz = szz0, d = d0;
            if(n-sz[in] >= szz) ans[szz] = max(ans[szz], d-dis+1);
        }
    }
    for(int x: v[nd]) if(x != ss){
        for(auto [szz0, d0]: s[x]){
            int d = d0, szz = szz0;
            if(n-sz[x] >= szz) ans[szz] = max(ans[szz], d-dis+1);
            if(!ms[szz].empty()){
                int cur = *ms[szz].rbegin();
                cur+=d;
                cur-=2*dis;
                cur++;
                ans[szz] = max(ans[szz], cur);
            }
        }
        for(auto [szz0, d0]: s[x]){
            int d = d0, szz = szz0;
            auto it = s[nd].lower_bound(make_pair(szz, 0));
            if(it == s[nd].end() || it->f != szz){
                s[nd].insert({szz, d});
                ms[szz].insert(d);
            }
            else if(it->sc < d){
                ms[szz].erase(ms[szz].find(it->sc));
                s[nd].erase(it);
                s[nd].insert({szz, d});
                ms[szz].insert(d);
            }
        }
        s[x].clear();
    }
    int szz = n-sz[nd]+1;
    if(!ms[szz].empty()) ans[szz] = max(ans[szz], (*ms[szz].rbegin())-dis+1);
    for(int i = mx+1; i <= sz[nd]; i++){
        ms[i].insert(dis);
        s[nd].insert({i, dis});
    }
    if(!keep){
        for(auto [szz0, d0]: s[nd]){
            int d = d0, szz = szz0;
            ms[szz].erase(ms[szz].find(d));
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    v.resize(n);
    ans.resize(n+1, 1);
    sz.resize(n, 1);
    s.resize(n);
    ms.resize(n+1);
    for(int i = 0; i < n-1; i++){
        int a, b; cin >> a >> b; a--, b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs_sz(0, -1);
    dfs(0, -1, 0, 1);
    for(int i = n-1; i >= 0; i--) ans[i] = max(ans[i], ans[i+1]);
    for(int i = 1; i <= n; i++){
        if(i%2 == 0) cout << ans[i/2] << "\n";
        else cout << "1\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 8 ms 1356 KB Output is correct
23 Correct 7 ms 1304 KB Output is correct
24 Correct 9 ms 1356 KB Output is correct
25 Correct 8 ms 1356 KB Output is correct
26 Correct 6 ms 1360 KB Output is correct
27 Correct 6 ms 1272 KB Output is correct
28 Correct 6 ms 1356 KB Output is correct
29 Correct 6 ms 1356 KB Output is correct
30 Correct 7 ms 1388 KB Output is correct
31 Correct 7 ms 1356 KB Output is correct
32 Correct 30 ms 1612 KB Output is correct
33 Correct 48 ms 1740 KB Output is correct
34 Correct 5 ms 1356 KB Output is correct
35 Correct 4 ms 1328 KB Output is correct
36 Correct 9 ms 1412 KB Output is correct
37 Correct 7 ms 1396 KB Output is correct
38 Correct 17 ms 1468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 8 ms 1356 KB Output is correct
23 Correct 7 ms 1304 KB Output is correct
24 Correct 9 ms 1356 KB Output is correct
25 Correct 8 ms 1356 KB Output is correct
26 Correct 6 ms 1360 KB Output is correct
27 Correct 6 ms 1272 KB Output is correct
28 Correct 6 ms 1356 KB Output is correct
29 Correct 6 ms 1356 KB Output is correct
30 Correct 7 ms 1388 KB Output is correct
31 Correct 7 ms 1356 KB Output is correct
32 Correct 30 ms 1612 KB Output is correct
33 Correct 48 ms 1740 KB Output is correct
34 Correct 5 ms 1356 KB Output is correct
35 Correct 4 ms 1328 KB Output is correct
36 Correct 9 ms 1412 KB Output is correct
37 Correct 7 ms 1396 KB Output is correct
38 Correct 17 ms 1468 KB Output is correct
39 Correct 585 ms 52432 KB Output is correct
40 Correct 572 ms 51448 KB Output is correct
41 Correct 590 ms 52772 KB Output is correct
42 Correct 657 ms 53676 KB Output is correct
43 Correct 624 ms 53552 KB Output is correct
44 Correct 676 ms 53572 KB Output is correct
45 Execution timed out 4064 ms 46484 KB Time limit exceeded
46 Halted 0 ms 0 KB -