Submission #602914

# Submission time Handle Problem Language Result Execution time Memory
602914 2022-07-23T12:37:50 Z AA_Surely Meetings 2 (JOI21_meetings2) C++14
100 / 100
607 ms 24100 KB
#include <bits/stdc++.h>

#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)

#define WTF cout << "WTF" << endl

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define PB push_back

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

using namespace std;

typedef long long LL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, PII> PPI;

typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

int n;
int sz[N], tmp[N], best[N], ans[N];
bool vis[N];
VI adj[N];

void init() {
    cin >> n;
    F0R(i, n - 1) {
        int u, v;
        cin >> u >> v;
        adj[--u].PB(--v);
        adj[v].PB(u);
    }

    return;
}

int getSz(int now, int p = -1) {
    sz[now] = 1;
    for(int on : adj[now]) if (!vis[on] && on != p) sz[now] += getSz(on, now);
    return sz[now];
}

int getCent(int now, int p, int nn) {
    for(int on : adj[now]) 
        if (on != p && !vis[on] && sz[on] > nn / 2) 
            return getCent(on, now, nn);
    return now;
}

void dfs(int now, int p, int h) {
    tmp[ sz[now] ] = max(tmp[ sz[now] ], h);
    for(int on : adj[now]) if (!vis[on] && on != p) dfs(on, now, h + 1);
    return;
}

void solve(int now) {
    getSz(now);
    int c = getCent(now, -1, sz[now]);
    getSz(c);

    vis[c] = 1;
    fill(best, best + sz[c] + 1, -INF);
    for(int on : adj[c]) if (!vis[on]) {
        fill(tmp, tmp + sz[on] + 1, -INF);
        dfs(on, c, 1);
        R0F(i, sz[on]) tmp[i] = max(tmp[i], tmp[i + 1]);
        FOR(i, 1, sz[on] + 1) {
            ans[i] = max(ans[i], best[i] + tmp[i] + 1);
            best[i] = max(best[i], tmp[i]);

            if (sz[c] - sz[on] >= i) ans[i] = max(ans[i], tmp[i] + 1);
        }
    }

    //cout << "ans until now "; FOR(i, 1, n + 1) cout << (i & 1 ? 1 : ans[i >> 1]) << ' '; cout << endl;

    for(int on : adj[c]) if (!vis[on]) solve(on);
    return;
}

int main() {
    IOS;

    init();
    solve(0);
    FOR(i, 1, n + 1) cout << (i & 1 ? 1 : max(1, ans[i >> 1])) << ' ';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 5032 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4964 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 5028 KB Output is correct
11 Correct 3 ms 4976 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5024 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 4928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 5032 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4964 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 5028 KB Output is correct
11 Correct 3 ms 4976 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5024 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 4928 KB Output is correct
22 Correct 6 ms 5168 KB Output is correct
23 Correct 6 ms 5160 KB Output is correct
24 Correct 5 ms 5204 KB Output is correct
25 Correct 6 ms 5204 KB Output is correct
26 Correct 6 ms 5168 KB Output is correct
27 Correct 6 ms 5204 KB Output is correct
28 Correct 6 ms 5204 KB Output is correct
29 Correct 6 ms 5204 KB Output is correct
30 Correct 5 ms 5204 KB Output is correct
31 Correct 6 ms 5164 KB Output is correct
32 Correct 7 ms 5332 KB Output is correct
33 Correct 15 ms 5332 KB Output is correct
34 Correct 4 ms 5204 KB Output is correct
35 Correct 7 ms 5164 KB Output is correct
36 Correct 6 ms 5204 KB Output is correct
37 Correct 4 ms 5204 KB Output is correct
38 Correct 5 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 5032 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4964 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 5028 KB Output is correct
11 Correct 3 ms 4976 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5024 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 4928 KB Output is correct
22 Correct 6 ms 5168 KB Output is correct
23 Correct 6 ms 5160 KB Output is correct
24 Correct 5 ms 5204 KB Output is correct
25 Correct 6 ms 5204 KB Output is correct
26 Correct 6 ms 5168 KB Output is correct
27 Correct 6 ms 5204 KB Output is correct
28 Correct 6 ms 5204 KB Output is correct
29 Correct 6 ms 5204 KB Output is correct
30 Correct 5 ms 5204 KB Output is correct
31 Correct 6 ms 5164 KB Output is correct
32 Correct 7 ms 5332 KB Output is correct
33 Correct 15 ms 5332 KB Output is correct
34 Correct 4 ms 5204 KB Output is correct
35 Correct 7 ms 5164 KB Output is correct
36 Correct 6 ms 5204 KB Output is correct
37 Correct 4 ms 5204 KB Output is correct
38 Correct 5 ms 5332 KB Output is correct
39 Correct 361 ms 16652 KB Output is correct
40 Correct 311 ms 16404 KB Output is correct
41 Correct 341 ms 16648 KB Output is correct
42 Correct 367 ms 16812 KB Output is correct
43 Correct 329 ms 16876 KB Output is correct
44 Correct 425 ms 16748 KB Output is correct
45 Correct 607 ms 20776 KB Output is correct
46 Correct 543 ms 24100 KB Output is correct
47 Correct 188 ms 16524 KB Output is correct
48 Correct 115 ms 16572 KB Output is correct
49 Correct 249 ms 17572 KB Output is correct
50 Correct 139 ms 17448 KB Output is correct
51 Correct 256 ms 23284 KB Output is correct