Submission #971794

# Submission time Handle Problem Language Result Execution time Memory
971794 2024-04-29T10:11:19 Z khanhtb Meetings 2 (JOI21_meetings2) C++14
100 / 100
318 ms 29640 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll base = 26;
const ll blocksz = 100;
const ll N = 2e5+8;
const ll lim = 1e5+8;
ll sz[N],h[N],mx[N],nmx[N],ans[N],n;
vi g[N];
bool del[N];
void cc(ll u, ll p){
    sz[u] = 1;
    for(ll v:g[u]){
        if(v == p || del[v]) continue;
        cc(v,u);
        sz[u] += sz[v];
    }
}
ll centroid(ll u, ll p, ll siz){
    for(ll v:g[u]){
        if(v != p && !del[v] && sz[v] > siz/2){
            return centroid(v,u,siz);
        }
    }
    return u;
}
void dfs(ll u, ll p){
    sz[u] = 1;
    for(ll v:g[u]){
        if(v != p && !del[v]){
            h[v] = h[u]+1;
            dfs(v,u);
            sz[u] += sz[v];
        }
    }
    nmx[sz[u]] = max(nmx[sz[u]],h[u]);
}
void decompose(ll u){
    cc(u,u);
    ll c = centroid(u,u,sz[u]);
    h[c] = 1;
    ll reset = 0;
    for(ll v:g[c]){
        if(!del[v]){
            h[v] = h[c]+1;
            dfs(v,c);
            reset = max(reset,sz[v]);
            for(ll i = sz[v]; i >= 0; i--) nmx[i] = max(nmx[i],nmx[i+1]);
            for(ll i = sz[v]; i >= 0; i--){
                ans[i<<1] = max(ans[i<<1],max(1LL,mx[i])+nmx[i]-1);
            }
            for(ll i = sz[v]; i >= 0; i--){
                mx[i] = max(mx[i],nmx[i]);
                nmx[i] = 0;
            }
        }
    }
    for(ll i = 0; i <= reset; i++) mx[i] = 0;
    del[c] = 1;
    for(ll v:g[c]) if(!del[v]) decompose(v);
}
void solve(){
    cin >> n;
    for(ll i = 1; i < n; i++){
        ll u,v;cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for(ll i = 1; i <= n; i++) ans[i] = 1;
    decompose(1);
    for(ll i = 1; i <= n; i++) cout << ans[i] << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    if(fopen("test.inp","r")){
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    int T = 1;
    // cin >> T;
    for(int tt = 1; tt <= T; tt++){
    	solve();
    	cout << '\n';
    }
}  

Compilation message

meetings2.cpp: In function 'int main()':
meetings2.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
meetings2.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 2 ms 10708 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 3 ms 10584 KB Output is correct
6 Correct 3 ms 10716 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10720 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10712 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 2 ms 10708 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 3 ms 10584 KB Output is correct
6 Correct 3 ms 10716 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10720 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10712 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10712 KB Output is correct
22 Correct 4 ms 10840 KB Output is correct
23 Correct 4 ms 10728 KB Output is correct
24 Correct 4 ms 10844 KB Output is correct
25 Correct 4 ms 10844 KB Output is correct
26 Correct 4 ms 10844 KB Output is correct
27 Correct 4 ms 10844 KB Output is correct
28 Correct 4 ms 10840 KB Output is correct
29 Correct 4 ms 10844 KB Output is correct
30 Correct 4 ms 10816 KB Output is correct
31 Correct 4 ms 10844 KB Output is correct
32 Correct 4 ms 10844 KB Output is correct
33 Correct 5 ms 11100 KB Output is correct
34 Correct 3 ms 10844 KB Output is correct
35 Correct 3 ms 10840 KB Output is correct
36 Correct 4 ms 10844 KB Output is correct
37 Correct 3 ms 10844 KB Output is correct
38 Correct 4 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 2 ms 10708 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 3 ms 10584 KB Output is correct
6 Correct 3 ms 10716 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10720 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10712 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10712 KB Output is correct
22 Correct 4 ms 10840 KB Output is correct
23 Correct 4 ms 10728 KB Output is correct
24 Correct 4 ms 10844 KB Output is correct
25 Correct 4 ms 10844 KB Output is correct
26 Correct 4 ms 10844 KB Output is correct
27 Correct 4 ms 10844 KB Output is correct
28 Correct 4 ms 10840 KB Output is correct
29 Correct 4 ms 10844 KB Output is correct
30 Correct 4 ms 10816 KB Output is correct
31 Correct 4 ms 10844 KB Output is correct
32 Correct 4 ms 10844 KB Output is correct
33 Correct 5 ms 11100 KB Output is correct
34 Correct 3 ms 10844 KB Output is correct
35 Correct 3 ms 10840 KB Output is correct
36 Correct 4 ms 10844 KB Output is correct
37 Correct 3 ms 10844 KB Output is correct
38 Correct 4 ms 10844 KB Output is correct
39 Correct 184 ms 23204 KB Output is correct
40 Correct 205 ms 23280 KB Output is correct
41 Correct 186 ms 23120 KB Output is correct
42 Correct 262 ms 23632 KB Output is correct
43 Correct 197 ms 23464 KB Output is correct
44 Correct 198 ms 23424 KB Output is correct
45 Correct 318 ms 27620 KB Output is correct
46 Correct 269 ms 29640 KB Output is correct
47 Correct 99 ms 23556 KB Output is correct
48 Correct 79 ms 24000 KB Output is correct
49 Correct 154 ms 23772 KB Output is correct
50 Correct 92 ms 23804 KB Output is correct
51 Correct 228 ms 29148 KB Output is correct