답안 #971523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971523 2024-04-28T18:01:32 Z _shr104 Meetings 2 (JOI21_meetings2) C++14
100 / 100
325 ms 28360 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 2e5+7;
ll sz[mxn], max_h[mxn], old_max_h[mxn], n, h[mxn], ans[mxn];
bool del[mxn];
vector<vector<ll>> g(mxn);
void dfs_sz(ll u, ll v) {sz[u] = 1; for (ll i : g[u]) {if (i != v && !del[i]) {dfs_sz(i,u); sz[u] += sz[i];}}}
ll dfs_ctr(ll u, ll v, ll szx) {for (ll i : g[u]) {if (i != v && !del[i] && sz[i] > szx/2) {return dfs_ctr(i,u,szx);}} return u;}
void dfs_mx(ll u, ll v)
{
    sz[u] = 1;
    for (ll i : g[u]) {if (i != v && !del[i]) {h[i] = h[u]+1; dfs_mx(i,u); sz[u] += sz[i];}}
    max_h[sz[u]] = max(max_h[sz[u]],h[u]);
}
void solve(ll u)
{
    dfs_sz(u,u); u = dfs_ctr(u,u,sz[u]); h[u] = 1; ll reset_bound = 0;
    for (ll i : g[u])
    {
        if (!del[i]) 
        {
            h[i] = 2; dfs_mx(i,u); reset_bound = max(reset_bound,sz[i]);
            for (ll j = sz[i]; j >= 0; j--) max_h[j] = max(max_h[j],max_h[j+1]);
            for (ll j = sz[i]; j >= 0; j--)
            {
                ans[j<<1] = max(ans[j<<1],max_h[j]+max(old_max_h[j],1LL)-1);
                old_max_h[j] = max(old_max_h[j],max_h[j]); max_h[j] = 0;
            }
        }   
    }
    for (ll i = reset_bound; i >= 0; i--) old_max_h[i] = max_h[i] = 0;
    del[u] = 1; for (ll i : g[u]) {if (!del[i]) {solve(i);}}
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
    cin >> n;
    for (ll i = 1; i < n; i++)
    {
        ll a, b; cin >> a >> b;
        g[a].pb(b); g[b].pb(a);
    }
    solve(1); for (ll i = 1; i <= n; i++) cout << max(ans[i],1LL) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 11100 KB Output is correct
2 Correct 2 ms 9048 KB Output is correct
3 Correct 2 ms 9048 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 2 ms 9048 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9272 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 2 ms 9052 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 2 ms 9264 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 3 ms 9052 KB Output is correct
21 Correct 2 ms 9048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 11100 KB Output is correct
2 Correct 2 ms 9048 KB Output is correct
3 Correct 2 ms 9048 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 2 ms 9048 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9272 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 2 ms 9052 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 2 ms 9264 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 3 ms 9052 KB Output is correct
21 Correct 2 ms 9048 KB Output is correct
22 Correct 4 ms 9308 KB Output is correct
23 Correct 4 ms 9304 KB Output is correct
24 Correct 5 ms 9304 KB Output is correct
25 Correct 4 ms 9308 KB Output is correct
26 Correct 4 ms 9308 KB Output is correct
27 Correct 4 ms 9392 KB Output is correct
28 Correct 4 ms 9504 KB Output is correct
29 Correct 4 ms 9308 KB Output is correct
30 Correct 6 ms 9288 KB Output is correct
31 Correct 4 ms 9308 KB Output is correct
32 Correct 5 ms 9564 KB Output is correct
33 Correct 4 ms 9564 KB Output is correct
34 Correct 4 ms 9308 KB Output is correct
35 Correct 4 ms 9308 KB Output is correct
36 Correct 4 ms 9308 KB Output is correct
37 Correct 4 ms 9308 KB Output is correct
38 Correct 3 ms 9396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 11100 KB Output is correct
2 Correct 2 ms 9048 KB Output is correct
3 Correct 2 ms 9048 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 2 ms 9048 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9272 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 2 ms 9052 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 2 ms 9264 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 3 ms 9052 KB Output is correct
21 Correct 2 ms 9048 KB Output is correct
22 Correct 4 ms 9308 KB Output is correct
23 Correct 4 ms 9304 KB Output is correct
24 Correct 5 ms 9304 KB Output is correct
25 Correct 4 ms 9308 KB Output is correct
26 Correct 4 ms 9308 KB Output is correct
27 Correct 4 ms 9392 KB Output is correct
28 Correct 4 ms 9504 KB Output is correct
29 Correct 4 ms 9308 KB Output is correct
30 Correct 6 ms 9288 KB Output is correct
31 Correct 4 ms 9308 KB Output is correct
32 Correct 5 ms 9564 KB Output is correct
33 Correct 4 ms 9564 KB Output is correct
34 Correct 4 ms 9308 KB Output is correct
35 Correct 4 ms 9308 KB Output is correct
36 Correct 4 ms 9308 KB Output is correct
37 Correct 4 ms 9308 KB Output is correct
38 Correct 3 ms 9396 KB Output is correct
39 Correct 199 ms 21584 KB Output is correct
40 Correct 169 ms 21172 KB Output is correct
41 Correct 239 ms 21516 KB Output is correct
42 Correct 213 ms 21844 KB Output is correct
43 Correct 183 ms 21760 KB Output is correct
44 Correct 230 ms 21588 KB Output is correct
45 Correct 325 ms 26028 KB Output is correct
46 Correct 261 ms 28360 KB Output is correct
47 Correct 87 ms 19744 KB Output is correct
48 Correct 66 ms 19904 KB Output is correct
49 Correct 170 ms 22340 KB Output is correct
50 Correct 83 ms 22468 KB Output is correct
51 Correct 179 ms 27828 KB Output is correct