답안 #971524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971524 2024-04-28T18:01:54 Z vjudge1 Meetings 2 (JOI21_meetings2) C++14
100 / 100
318 ms 25884 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 2 ms 11100 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 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 9308 KB Output is correct
11 Correct 2 ms 9052 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 9188 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 2 ms 9052 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 2 ms 9048 KB Output is correct
21 Correct 2 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11100 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 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 9308 KB Output is correct
11 Correct 2 ms 9052 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 9188 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 2 ms 9052 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 2 ms 9048 KB Output is correct
21 Correct 2 ms 9052 KB Output is correct
22 Correct 4 ms 9308 KB Output is correct
23 Correct 4 ms 9308 KB Output is correct
24 Correct 4 ms 9308 KB Output is correct
25 Correct 5 ms 9308 KB Output is correct
26 Correct 4 ms 9304 KB Output is correct
27 Correct 4 ms 9472 KB Output is correct
28 Correct 3 ms 9308 KB Output is correct
29 Correct 4 ms 9308 KB Output is correct
30 Correct 4 ms 9308 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 9560 KB Output is correct
34 Correct 4 ms 9304 KB Output is correct
35 Correct 4 ms 9308 KB Output is correct
36 Correct 4 ms 9468 KB Output is correct
37 Correct 4 ms 9308 KB Output is correct
38 Correct 4 ms 9308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11100 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 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 9308 KB Output is correct
11 Correct 2 ms 9052 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 9188 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 2 ms 9052 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 2 ms 9048 KB Output is correct
21 Correct 2 ms 9052 KB Output is correct
22 Correct 4 ms 9308 KB Output is correct
23 Correct 4 ms 9308 KB Output is correct
24 Correct 4 ms 9308 KB Output is correct
25 Correct 5 ms 9308 KB Output is correct
26 Correct 4 ms 9304 KB Output is correct
27 Correct 4 ms 9472 KB Output is correct
28 Correct 3 ms 9308 KB Output is correct
29 Correct 4 ms 9308 KB Output is correct
30 Correct 4 ms 9308 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 9560 KB Output is correct
34 Correct 4 ms 9304 KB Output is correct
35 Correct 4 ms 9308 KB Output is correct
36 Correct 4 ms 9468 KB Output is correct
37 Correct 4 ms 9308 KB Output is correct
38 Correct 4 ms 9308 KB Output is correct
39 Correct 203 ms 19276 KB Output is correct
40 Correct 190 ms 18864 KB Output is correct
41 Correct 218 ms 19152 KB Output is correct
42 Correct 182 ms 19248 KB Output is correct
43 Correct 210 ms 19244 KB Output is correct
44 Correct 196 ms 19024 KB Output is correct
45 Correct 318 ms 23312 KB Output is correct
46 Correct 260 ms 25884 KB Output is correct
47 Correct 80 ms 17096 KB Output is correct
48 Correct 71 ms 17792 KB Output is correct
49 Correct 166 ms 19800 KB Output is correct
50 Correct 82 ms 20124 KB Output is correct
51 Correct 167 ms 25288 KB Output is correct