QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#433048#3100. Meetings 2snpmrnhlol4 9ms9168kbC++143.5kb2024-06-07 22:57:082024-06-07 22:57:08

Judging History

你现在查看的是最新测评结果

  • [2024-06-07 22:57:08]
  • 评测
  • 测评结果:4
  • 用时:9ms
  • 内存:9168kb
  • [2024-06-07 22:57:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5;
const int inf = 2e9;
vector <int> e[N];
int bad[N];
int sub[N];
int gbsub[N];
int pr[N];
int ans[N + 1];
int n;
void dfs(int node, int p){
    gbsub[node] = 1;
    pr[node] = p;
    for(auto i:e[node]){
        if(i == p)continue;
        dfs(i,node);
        gbsub[node]+=gbsub[i];
    }
}
int get(int node, int p){
    if(pr[node] == p){
        return gbsub[node];
    }else{
        return n - gbsub[p];
    }
}
void cendecomp(int node){
    vector <array<int,3>> nodes;
    int sz = 0;
    int cen = -1,cennr = inf;
    auto dfs = [&](auto self, int node, int p) -> void{
        sz++;
        for(auto i:e[node]){
            if(i == p || bad[i])continue;
            self(self, i, node);
        }
    };
    auto dfs2 = [&](auto self, int node, int p) -> void{
        sub[node] = 1;
        int mx = -1;
        for(auto i:e[node]){
            if(i == p || bad[i])continue;
            self(self, i, node);
            sub[node]+=sub[i];
            mx = max(mx,sub[i]);
        }
        mx = max(mx,sz - sub[node]);
        if(mx < cennr){
            mx = cennr;
            cen = node;
        }
    };
    auto dfs3 = [&](auto self, int node, int p, int dpth, int orig) -> void{
        int nr = min(get(node,p),get(cen,orig));
        ans[2*nr] = max(dpth,ans[2*nr]);
        for(auto i:e[node]){
            if(i == p || bad[i])continue;
            self(self, i, node, dpth + 1, orig);
        }
    };
    auto dfs4 = [&](auto self, int node, int p, int dpth, int orig) -> void{
        nodes.push_back({orig,dpth,get(node,p)});
        for(auto i:e[node]){
            if(i == p || bad[i])continue;
            self(self, i, node, dpth + 1, orig);
        }
    };
    dfs(dfs, node, -1);
    dfs2(dfs2, node, -1);
    for(auto i:e[cen]){
        if(bad[i])continue;
        dfs3(dfs3, i, cen, 2, i);
        dfs4(dfs4, i, cen, 1, i);
    }
    sort(nodes.begin(),nodes.end(),[&](auto a,auto b){
         return a[2] > b[2];
    });
    array <int,3> best[2] = {{-1,-1,-1},{-1,-1,-1}};
    for(int i = 0;i < nodes.size();i++){
        bool ok = 0;
        for(int j = 0;j < 2;j++){
            if(best[j][2] != -1 && nodes[i][2] != -1 && nodes[i][0] != best[j][0]){
                ans[2*nodes[i][2]] = max(ans[2*nodes[i][2]],nodes[i][1] + best[j][1] + 1);
            }
            if(best[j][0] == nodes[i][0]){
                best[j][1] = max(best[j][1],nodes[i][1]);
                if(best[1][1] > best[0][0])swap(best[0],best[1]);
                ok = 1;
            }
        }
        if(!ok){
            if(best[0][1] < nodes[i][1]){
                best[1] = best[0];
                best[0] = nodes[i];
            }else if(best[1][1] < nodes[i][1]){
                best[1] = nodes[i];
            }
        }
    }
    bad[cen] = 1;
    for(auto i:e[cen]){
        if(bad[i])continue;
        cendecomp(i);
    }
}
void solve(){
    cin>>n;
    for(int i = 0;i < n - 1;i++){
        int u,w;
        cin>>u>>w;
        u--;w--;
        e[w].push_back(u);
        e[u].push_back(w);
    }
    dfs(0, -1);
    cendecomp(0);
    for(int i = n;i >= 2;i--){
        if(i%2 == 0)ans[i] = max(ans[i],ans[i + 2]);
    }
    for(int i = 1;i <= n;i++){
        if(i%2 == 1)cout<<1<<'\n';
        else{
            cout<<max(ans[i],1)<<'\n';
        }
    }
}
int main(){
    int t;
    t = 1;
    while(t--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 3ms
memory: 8304kb

input:

1

output:

1

result:

ok single line: '1'

Test #2:

score: 4
Accepted
time: 3ms
memory: 8300kb

input:

2
2 1

output:

1
2

result:

ok 2 lines

Test #3:

score: 4
Accepted
time: 0ms
memory: 8532kb

input:

3
1 3
3 2

output:

1
3
1

result:

ok 3 lines

Test #4:

score: 4
Accepted
time: 2ms
memory: 8312kb

input:

14
12 14
12 9
14 2
12 6
12 7
6 4
3 4
1 4
12 8
13 1
10 12
11 6
6 5

output:

1
7
1
5
1
3
1
3
1
2
1
2
1
2

result:

ok 14 lines

Test #5:

score: 4
Accepted
time: 3ms
memory: 8476kb

input:

14
10 14
3 10
14 13
1 3
3 5
3 11
12 14
14 6
11 8
2 3
7 8
9 7
1 4

output:

1
8
1
6
1
5
1
4
1
2
1
1
1
1

result:

ok 14 lines

Test #6:

score: 4
Accepted
time: 0ms
memory: 8220kb

input:

14
8 13
13 10
13 7
6 8
5 7
10 4
9 5
12 8
6 2
4 11
5 1
9 3
4 14

output:

1
8
1
6
1
5
1
4
1
2
1
1
1
1

result:

ok 14 lines

Test #7:

score: 4
Accepted
time: 3ms
memory: 8300kb

input:

14
9 2
9 8
3 8
14 9
13 3
1 2
5 2
9 6
4 2
4 11
10 6
12 10
7 9

output:

1
7
1
5
1
3
1
2
1
2
1
1
1
1

result:

ok 14 lines

Test #8:

score: 4
Accepted
time: 0ms
memory: 8488kb

input:

15
10 7
15 7
14 7
15 11
6 15
10 8
14 2
4 8
15 1
3 6
4 13
1 9
5 2
8 12

output:

1
8
1
6
1
4
1
4
1
3
1
2
1
1
1

result:

ok 15 lines

Test #9:

score: 4
Accepted
time: 0ms
memory: 8364kb

input:

16
11 8
11 10
10 1
11 2
15 8
13 10
9 2
2 4
8 6
2 7
3 7
12 9
6 16
9 14
12 5

output:

1
8
1
6
1
4
1
4
1
2
1
2
1
2
1
2

result:

ok 16 lines

Test #10:

score: 4
Accepted
time: 0ms
memory: 8248kb

input:

16
7 11
16 11
11 6
1 16
1 14
1 3
12 3
14 8
12 10
5 16
6 9
6 4
9 2
15 4
2 13

output:

1
10
1
8
1
6
1
4
1
4
1
4
1
2
1
2

result:

ok 16 lines

Test #11:

score: 4
Accepted
time: 3ms
memory: 8484kb

input:

16
13 3
16 13
16 5
16 8
3 12
11 16
14 8
15 12
3 10
10 2
16 1
6 10
11 9
8 4
1 7

output:

1
7
1
5
1
5
1
3
1
3
1
3
1
2
1
1

result:

ok 16 lines

Test #12:

score: 4
Accepted
time: 0ms
memory: 8304kb

input:

16
12 13
13 3
14 3
7 14
9 3
11 13
14 8
2 14
14 6
2 16
4 3
7 5
16 1
9 10
13 15

output:

1
7
1
5
1
4
1
3
1
2
1
2
1
2
1
2

result:

ok 16 lines

Test #13:

score: 4
Accepted
time: 3ms
memory: 8468kb

input:

16
1 7
15 1
8 1
15 12
7 2
1 13
13 14
12 3
3 16
11 3
9 3
10 12
2 5
6 7
9 4

output:

1
9
1
7
1
5
1
5
1
4
1
3
1
3
1
2

result:

ok 16 lines

Test #14:

score: 4
Accepted
time: 0ms
memory: 8296kb

input:

14
8 11
11 5
7 5
7 3
3 12
12 2
2 14
14 6
3 1
9 12
6 13
10 1
4 7

output:

1
10
1
8
1
6
1
4
1
3
1
2
1
1

result:

ok 14 lines

Test #15:

score: 4
Accepted
time: 3ms
memory: 8312kb

input:

14
6 8
9 8
1 9
1 3
3 10
5 10
13 5
11 13
11 12
12 14
7 14
4 7
4 2

output:

1
14
1
12
1
10
1
8
1
6
1
4
1
2

result:

ok 14 lines

Test #16:

score: 4
Accepted
time: 3ms
memory: 8516kb

input:

15
4 7
7 3
15 7
7 14
10 7
7 1
13 7
8 7
7 9
6 7
1 5
4 12
2 3
10 11

output:

1
5
1
3
1
1
1
1
1
1
1
1
1
1
1

result:

ok 15 lines

Test #17:

score: 4
Accepted
time: 3ms
memory: 8300kb

input:

16
14 7
15 14
14 5
14 2
14 12
11 14
13 14
14 10
3 14
14 9
14 16
14 6
1 14
14 8
4 14

output:

1
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 16 lines

Test #18:

score: 4
Accepted
time: 3ms
memory: 8284kb

input:

16
4 9
9 10
10 6
16 6
4 5
5 14
14 15
5 7
8 14
14 13
11 5
5 12
5 2
5 1
3 5

output:

1
8
1
6
1
5
1
4
1
2
1
1
1
1
1
1

result:

ok 16 lines

Test #19:

score: 4
Accepted
time: 3ms
memory: 8312kb

input:

15
4 15
4 10
1 4
5 4
4 12
14 4
11 4
4 13
13 9
6 9
6 7
2 13
2 8
3 2

output:

1
6
1
4
1
3
1
2
1
2
1
2
1
2
1

result:

ok 15 lines

Test #20:

score: 4
Accepted
time: 0ms
memory: 8344kb

input:

16
1 2
2 5
12 2
2 15
14 2
2 11
6 2
10 2
10 4
13 4
16 13
10 9
9 7
9 3
8 3

output:

1
7
1
5
1
3
1
3
1
2
1
2
1
2
1
2

result:

ok 16 lines

Test #21:

score: 4
Accepted
time: 0ms
memory: 8308kb

input:

15
11 15
15 6
15 12
15 2
15 14
9 15
7 15
13 15
4 1
4 3
13 3
8 13
10 8
5 10

output:

1
7
1
5
1
3
1
2
1
2
1
2
1
2
1

result:

ok 15 lines

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #22:

score: 16
Accepted
time: 9ms
memory: 8852kb

input:

3985
2388 2281
2388 3669
2448 3669
2448 2962
3147 2448
2166 2388
209 3147
2325 2388
1584 3147
1349 3669
3525 3147
2962 2698
1349 660
2281 553
3454 3147
2325 3651
3339 2281
2281 3565
1584 1621
1584 2118
819 3339
72 2166
2025 660
553 2331
3266 209
2166 2930
2432 3454
3677 3525
368 1349
553 519
3677 28...

output:

1
34
1
32
1
31
1
30
1
29
1
28
1
28
1
28
1
28
1
27
1
27
1
27
1
27
1
27
1
27
1
27
1
26
1
26
1
25
1
25
1
24
1
24
1
23
1
23
1
23
1
23
1
22
1
22
1
22
1
22
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
18
1
18
1
18
1
18
1
18
...

result:

ok 3985 lines

Test #23:

score: 16
Accepted
time: 8ms
memory: 8668kb

input:

3986
1021 3515
726 1021
757 1021
1483 1021
483 1483
3239 483
1021 2531
757 1622
483 2480
90 1622
483 3977
90 3459
757 1821
761 3239
3022 757
726 669
2327 90
3585 3022
279 3977
3977 2484
846 1622
1021 2639
2754 3515
1176 1021
96 483
3585 3604
2327 1741
2327 1759
2480 2457
2327 306
3977 3422
1233 3977...

output:

1
35
1
33
1
31
1
29
1
29
1
28
1
28
1
28
1
26
1
26
1
26
1
25
1
24
1
24
1
24
1
24
1
24
1
24
1
23
1
23
1
23
1
22
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
19
1
19
1
19
1
19
1
19
1
19
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
...

result:

ok 3986 lines

Test #24:

score: 16
Accepted
time: 9ms
memory: 8852kb

input:

3942
2742 1586
1768 2742
1586 3325
1768 673
3166 673
1392 3166
1764 2742
3846 673
673 24
24 1880
3325 2461
180 24
2461 1825
1586 3232
369 3325
2322 24
180 1198
36 1825
1880 865
3625 865
3325 2289
3625 1318
1825 1393
1309 36
88 1768
36 570
2588 570
36 3621
3925 1764
1090 2742
674 570
180 3150
118 362...

output:

1
43
1
41
1
39
1
37
1
37
1
36
1
35
1
34
1
34
1
34
1
33
1
33
1
32
1
32
1
32
1
31
1
31
1
31
1
30
1
30
1
30
1
29
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
28
1
27
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
26
1
24
1
24
1
24
1
24
...

result:

ok 3942 lines

Test #25:

score: 16
Accepted
time: 3ms
memory: 9168kb

input:

3960
750 291
750 1350
2287 291
2287 1155
590 1350
1350 2483
590 2452
3626 291
291 249
2287 570
491 590
2491 1155
1155 870
1155 2397
750 259
491 3488
3488 1848
3107 750
705 3626
570 3649
3411 2397
2483 3770
1415 590
454 3488
2960 1350
259 2224
1415 648
2254 491
2864 705
249 1567
275 1350
2757 491
107...

output:

1
30
1
28
1
27
1
25
1
24
1
23
1
22
1
22
1
22
1
20
1
20
1
20
1
20
1
20
1
19
1
19
1
19
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
17
1
17
1
17
1
17
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
15
1
15
1
15
1
15
1
14
1
14
1
14
1
14
1
14
1
14
1
14
1
14
...

result:

ok 3960 lines

Test #26:

score: 16
Accepted
time: 3ms
memory: 8824kb

input:

3949
3764 3701
2864 3701
1554 3701
578 2864
3701 3539
3539 1974
3539 88
3701 1236
578 2111
3012 88
1895 3764
273 1236
1174 2864
222 578
1895 3149
3539 2629
3429 2111
1544 3429
1554 190
2069 2111
1236 3542
578 3658
2762 1974
3424 1895
1133 2762
3658 3527
1895 696
2721 2762
3539 452
88 3610
2721 3147
...

output:

1
31
1
29
1
29
1
27
1
26
1
26
1
25
1
24
1
24
1
24
1
23
1
23
1
22
1
21
1
21
1
21
1
21
1
21
1
21
1
20
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
16
1
16
1
16
1
15
1
14
1
14
1
14
1
14
1
14
1
14
1
14
1
13
1
13
1
13
...

result:

ok 3949 lines

Test #27:

score: 16
Accepted
time: 4ms
memory: 8656kb

input:

4000
3523 3550
3523 3231
1960 3523
308 3550
3766 1960
3638 3550
1398 308
308 172
3550 3214
3638 3212
1973 3231
448 172
3214 1726
2761 3550
1792 3212
1973 538
3231 1838
3491 2761
172 1551
2340 448
1484 2761
3214 2034
448 2208
189 3212
800 3550
3214 1033
189 1504
2051 3638
941 1726
1805 1398
230 538
3...

output:

1
34
1
32
1
31
1
29
1
29
1
28
1
27
1
26
1
26
1
26
1
26
1
26
1
25
1
25
1
25
1
24
1
24
1
24
1
24
1
24
1
22
1
22
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
20
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
19
1
18
1
18
1
18
1
18
1
18
...

result:

ok 4000 lines

Test #28:

score: 16
Accepted
time: 9ms
memory: 8700kb

input:

4000
2627 2898
2898 314
3345 2627
314 2466
3345 1095
3031 314
1095 2542
3074 2627
3391 3031
2898 89
3314 2898
3415 2898
2542 12
49 314
2361 314
2131 2361
3031 920
2131 2303
3074 368
3915 1095
565 12
89 284
2303 1975
2312 2466
2131 3901
3481 12
3712 2627
49 3860
350 2131
3031 3489
686 2361
3415 340
3...

output:

1
33
1
31
1
29
1
29
1
28
1
26
1
26
1
26
1
26
1
24
1
24
1
24
1
24
1
24
1
24
1
23
1
22
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
20
1
19
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
17
1
17
1
17
1
17
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
...

result:

ok 4000 lines

Test #29:

score: 16
Accepted
time: 8ms
memory: 8620kb

input:

4000
2089 2753
2753 1171
3685 2753
2089 584
2089 2113
2865 3685
2113 3150
1828 2089
2753 170
227 2089
157 2753
584 906
3150 2429
2113 2332
227 2972
227 1358
2478 906
2113 3791
170 273
1171 3846
1358 3727
2972 1844
1989 2865
3791 2995
2933 3685
1171 3992
584 682
2865 1771
256 3150
796 584
614 1844
27...

output:

1
31
1
29
1
27
1
26
1
26
1
26
1
25
1
25
1
24
1
24
1
23
1
23
1
23
1
22
1
22
1
20
1
19
1
18
1
18
1
18
1
18
1
18
1
18
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
14
1
13
1
13
1
13
1
13
1
13
1
13
1
13
1
13
1
13
1
13
...

result:

ok 4000 lines

Test #30:

score: 16
Accepted
time: 8ms
memory: 8628kb

input:

4000
3023 347
697 347
697 3559
3559 1639
3344 697
347 3237
2644 347
697 3054
64 3023
697 767
2417 2644
1993 3237
380 2417
140 3054
2900 1993
1483 3559
1515 3054
3395 2417
347 3304
697 2805
3559 3519
2644 196
3989 2417
2805 2464
1326 2417
2900 1703
2496 697
767 3098
790 196
954 1326
219 1639
790 31
3...

output:

1
32
1
30
1
28
1
27
1
26
1
26
1
24
1
24
1
23
1
23
1
23
1
22
1
22
1
22
1
21
1
21
1
20
1
20
1
20
1
20
1
19
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
17
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
1
15
...

result:

ok 4000 lines

Test #31:

score: 0
Wrong Answer
time: 8ms
memory: 8632kb

input:

4000
609 943
2191 943
609 3385
3560 609
3385 3309
3278 609
609 3625
2260 2191
943 1008
1626 2191
2332 3278
1305 609
1386 3625
1008 503
3278 45
3309 1355
3222 3625
2260 3488
2547 3222
2260 1154
3385 2503
1038 3625
2503 3211
1305 2011
2332 3944
1355 190
2187 3385
2187 1252
3211 625
1843 3488
943 2650
...

output:

1
33
1
31
1
29
1
27
1
26
1
26
1
26
1
25
1
24
1
23
1
22
1
22
1
22
1
22
1
21
1
20
1
20
1
20
1
20
1
20
1
19
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
18
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
17
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
16
1
15
1
15
1
15
1
15
1
15
1
15
...

result:

wrong answer 44th lines differ - expected: '19', found: '18'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%