답안 #971795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971795 2024-04-29T10:11:51 Z vjudge1 Meetings 2 (JOI21_meetings2) C++14
100 / 100
314 ms 27248 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10840 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 10584 KB Output is correct
13 Correct 3 ms 10584 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 2 ms 10584 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 10668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10840 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 10584 KB Output is correct
13 Correct 3 ms 10584 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 2 ms 10584 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 10668 KB Output is correct
22 Correct 5 ms 10844 KB Output is correct
23 Correct 4 ms 10840 KB Output is correct
24 Correct 4 ms 10844 KB Output is correct
25 Correct 3 ms 10684 KB Output is correct
26 Correct 4 ms 10844 KB Output is correct
27 Correct 5 ms 11100 KB Output is correct
28 Correct 4 ms 10844 KB Output is correct
29 Correct 4 ms 10844 KB Output is correct
30 Correct 4 ms 10844 KB Output is correct
31 Correct 4 ms 10844 KB Output is correct
32 Correct 4 ms 10844 KB Output is correct
33 Correct 4 ms 10844 KB Output is correct
34 Correct 3 ms 10844 KB Output is correct
35 Correct 3 ms 10684 KB Output is correct
36 Correct 3 ms 10844 KB Output is correct
37 Correct 3 ms 10844 KB Output is correct
38 Correct 3 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10840 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 10584 KB Output is correct
13 Correct 3 ms 10584 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 2 ms 10584 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 10668 KB Output is correct
22 Correct 5 ms 10844 KB Output is correct
23 Correct 4 ms 10840 KB Output is correct
24 Correct 4 ms 10844 KB Output is correct
25 Correct 3 ms 10684 KB Output is correct
26 Correct 4 ms 10844 KB Output is correct
27 Correct 5 ms 11100 KB Output is correct
28 Correct 4 ms 10844 KB Output is correct
29 Correct 4 ms 10844 KB Output is correct
30 Correct 4 ms 10844 KB Output is correct
31 Correct 4 ms 10844 KB Output is correct
32 Correct 4 ms 10844 KB Output is correct
33 Correct 4 ms 10844 KB Output is correct
34 Correct 3 ms 10844 KB Output is correct
35 Correct 3 ms 10684 KB Output is correct
36 Correct 3 ms 10844 KB Output is correct
37 Correct 3 ms 10844 KB Output is correct
38 Correct 3 ms 10844 KB Output is correct
39 Correct 180 ms 20820 KB Output is correct
40 Correct 181 ms 20568 KB Output is correct
41 Correct 179 ms 20648 KB Output is correct
42 Correct 172 ms 20920 KB Output is correct
43 Correct 183 ms 20816 KB Output is correct
44 Correct 197 ms 20992 KB Output is correct
45 Correct 314 ms 24968 KB Output is correct
46 Correct 288 ms 27248 KB Output is correct
47 Correct 79 ms 20784 KB Output is correct
48 Correct 79 ms 21384 KB Output is correct
49 Correct 157 ms 21076 KB Output is correct
50 Correct 80 ms 21292 KB Output is correct
51 Correct 152 ms 26824 KB Output is correct