QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#29876#2905. Tree HoppingGeorge_Plover#AC ✓93ms20340kbC++201.4kb2022-04-23 12:27:032022-04-28 15:56:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-28 15:56:57]
  • 评测
  • 测评结果:AC
  • 用时:93ms
  • 内存:20340kb
  • [2022-04-23 12:27:03]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define per(i, r, l) for (int i = r; i >= l; --i)
using namespace std;
const int N = 100005;
int T;
int n;
vector<int> E[N];
int dep[N];
int f[N][20];
void dfs(int u, int fa) {
    dep[u] = dep[fa] + 1;
    f[u][0] = fa;
    rep(i, 1, 19) { f[u][i] = f[f[u][i - 1]][i - 1]; }
    for (auto v : E[u]) {
        if (v == fa) continue;
        dfs(v, u);
    }
}
int lca(int x, int y) {
    if (dep[x] < dep[y]) swap(x, y);
    per(i, 19, 0) {
        if (dep[x] - dep[y] >= (1 << i)) x = f[x][i];
    }
    per(i, 19, 0) {
        if (f[x][i] != f[y][i]) {
            x = f[x][i], y = f[y][i];
        }
    }
    return x == y ? x : f[x][0];
}
int dis(int x, int y) { return dep[x] + dep[y] - dep[lca(x, y)] * 2; }

int p[N];

int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        rep(i, 1, n) { E[i].clear(); }
        rep(i, 1, n - 1) {
            int u, v;
            scanf("%d%d", &u, &v);
            E[u].push_back(v);
            E[v].push_back(u);
        }
        dfs(1, 0);
        rep(i, 1, n) { scanf("%d", &p[i]); }
        bool ans = true;
        rep(i, 1, n - 1) {
            // printf("%d ", dis(p[i], p[i + 1]));
            if (dis(p[i], p[i + 1]) > 3) ans = false;
        }
        printf("%d\n", ans);
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 90ms
memory: 19756kb

input:

1
100000
82434 91867
26281 85594
55906 58160
77741 84042
9428 18333
12828 74753
77689 99092
38286 54810
20105 49007
46686 99681
2706 7961
3181 52536
220 10994
47988 73136
9692 62150
33736 95126
26464 42470
27856 35956
21730 25755
37051 37915
30853 92883
41489 72370
21569 85241
7003 70312
14566 64955...

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 91ms
memory: 17840kb

input:

1
100000
11303 71484
4529 70330
1552 87041
41453 92339
21465 71516
19667 39857
21959 58716
31932 84665
8053 50446
29022 90760
87296 95567
75516 96539
8038 35993
75926 88583
20508 49007
2834 31547
22687 29886
71794 83507
17697 42712
22396 95499
57654 59390
9926 59724
77735 84162
38056 56700
34646 852...

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 71ms
memory: 18500kb

input:

1
100000
50499 88655
47392 81287
36361 66187
45853 65264
4748 14073
5399 51911
60036 94465
35297 37198
75162 83826
63387 82046
1438 20159
7075 19977
68862 77569
14608 50627
26978 52577
74081 80136
13555 76986
18365 61979
20856 23260
97435 98359
57880 64546
59659 81110
37015 51355
29278 81962
31789 3...

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 79ms
memory: 18328kb

input:

1
100000
89954 94897
61146 74499
29706 97870
806 98329
37648 48068
21676 87460
38744 71966
18811 34570
21414 23704
50602 80814
49218 66891
80134 88526
39946 64804
73181 91743
18669 30527
21935 81884
42699 89451
16825 55365
1156 38267
1789 54324
70908 96541
71002 84415
34102 39357
56250 99915
8968 44...

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 76ms
memory: 18292kb

input:

1
100000
17760 53992
25523 60557
25449 60674
14039 64859
9258 25449
60568 80600
9906 81773
51671 90773
89625 95458
3449 30577
33800 58699
26021 51779
11102 92494
6568 74509
8470 16419
48838 70812
53907 56306
39122 98432
15872 32789
11452 75192
14345 63018
5332 76083
40289 44105
14011 94061
29750 895...

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 64ms
memory: 18332kb

input:

1
100000
38948 89798
14334 62806
5338 17015
25474 47123
17015 98459
26810 98892
18596 94533
59407 70032
39086 81778
38069 93264
41133 56898
2434 78685
76503 89798
46161 48839
66825 78111
29593 44371
23556 85793
18484 93045
37045 61644
5461 11365
16608 76538
42928 75813
209 51842
17702 43099
68727 93...

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 55ms
memory: 17744kb

input:

1
100000
7797 35286
7797 95507
7797 92408
7797 35660
7797 59959
7797 95191
7797 83597
7797 30917
7797 64024
4434 7797
7797 65782
7797 34833
7797 98901
7797 80759
7797 85843
7797 55166
7797 95661
7797 50297
7797 95487
7797 37600
7797 55163
7797 91951
7797 38090
7797 70838
7797 28406
7797 26529
7797 3...

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 55ms
memory: 17980kb

input:

1
100000
19721 95065
19721 20347
19721 23110
45011 99470
19721 67831
19721 53287
53343 99470
89489 99470
31896 99470
88964 99470
19721 69366
82976 99470
18893 19721
5527 99470
19721 55997
19182 19721
25536 99470
3368 99470
7813 99470
28864 99470
2061 99470
19721 22257
19721 89534
81524 99470
20939 9...

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 65ms
memory: 17976kb

input:

1
100000
32729 40509
40509 79197
47470 73945
14921 18709
40559 67429
24715 67429
47470 54744
15549 47470
67429 95832
43877 51827
67429 92426
14921 22354
51827 55019
37182 40509
47470 90854
6157 40509
14921 37969
20631 47470
31408 47470
14921 38212
51827 63998
24741 47470
67429 71462
47470 86837
5984...

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 79ms
memory: 18360kb

input:

1
100000
52560 64636
38628 52560
17386 92892
16746 58170
63832 85452
63832 95872
19381 44650
44650 49535
48621 91858
6850 79607
38910 63832
16746 26195
35342 51929
35006 72308
17386 66607
40507 52560
16746 72367
22092 44650
30442 44650
1363 16746
23982 79607
17386 44006
63832 76837
44650 87113
48621...

output:

1

result:

ok single line: '1'

Test #11:

score: 0
Accepted
time: 60ms
memory: 18256kb

input:

1
100000
798 89195
65428 78279
24948 47324
34121 61118
20027 76309
84098 97614
56927 69819
38987 47849
36658 45514
16991 54660
52047 94797
5009 33795
25819 42015
8304 9025
26430 30082
23835 32023
68743 70064
844 12390
27227 84584
4720 80337
56112 80751
83693 89700
20027 78996
53193 89210
8948 15826
...

output:

1

result:

ok single line: '1'

Test #12:

score: 0
Accepted
time: 61ms
memory: 18468kb

input:

1
100000
44066 72554
12532 23378
3729 9804
3231 47201
47073 91280
22554 96781
44366 59860
22614 25868
95465 99232
7283 11743
28828 56324
18397 21828
62785 76261
57105 60629
4399 65381
4624 19215
33370 36554
31957 99455
5385 14037
37130 73195
1691 60670
43206 45484
25081 91280
65826 74951
52611 76889...

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 44ms
memory: 17892kb

input:

1
100000
1 99999
2 100000
3 99999
4 100000
5 99999
6 100000
7 99999
8 100000
9 99999
10 100000
11 99999
12 100000
13 99999
14 100000
15 99999
16 100000
17 99999
18 100000
19 99999
20 100000
21 99999
22 100000
23 99999
24 100000
25 99999
26 100000
27 99999
28 100000
29 99999
30 100000
31 99999
32 100...

output:

1

result:

ok single line: '1'

Test #14:

score: 0
Accepted
time: 31ms
memory: 17872kb

input:

1
100000
1 2
1 3
2 4
1 5
2 6
1 7
2 8
1 9
2 10
1 11
2 12
1 13
2 14
1 15
2 16
1 17
2 18
1 19
2 20
1 21
2 22
1 23
2 24
1 25
2 26
1 27
2 28
1 29
2 30
1 31
2 32
1 33
2 34
1 35
2 36
1 37
2 38
1 39
2 40
1 41
2 42
1 43
2 44
1 45
2 46
1 47
2 48
1 49
2 50
1 51
2 52
1 53
2 54
1 55
2 56
1 57
2 58
1 59
2 60
1 61...

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 83ms
memory: 19528kb

input:

1
100000
25293 94869
10022 68793
1389 92726
58206 68958
2071 23917
3191 89315
36504 57054
34359 85245
25085 63144
66742 70119
66119 81635
34210 91288
27700 37427
31003 71698
22042 66192
17272 68278
9299 14650
8986 12552
93129 98744
28882 77559
28891 30119
21711 55750
54122 81975
51886 68759
42365 92...

output:

0

result:

ok single line: '0'

Test #16:

score: 0
Accepted
time: 70ms
memory: 17840kb

input:

1
100000
50205 57834
54914 97194
72952 86838
27861 76617
31387 77783
16810 71916
42438 88429
28292 96268
24749 92279
96848 97972
8932 18218
41227 95959
59500 99420
69115 85468
7429 41243
4473 24476
7461 58840
93716 97696
1916 53141
69370 79136
31374 66915
60487 81019
51140 63534
53255 61878
3602 661...

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 71ms
memory: 18436kb

input:

1
100000
10002 92504
31473 42558
27112 74621
60493 89465
27641 82983
21568 57447
63322 85990
10391 86795
23475 32755
32055 47952
15574 57270
7636 58997
22018 29600
81261 94883
22998 43691
76173 96795
70781 90629
52887 99767
23155 35719
59131 91302
13216 43372
33997 93563
70642 80867
22801 24493
9755...

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 76ms
memory: 18372kb

input:

1
100000
9332 35259
77836 87537
23942 32579
25739 76497
80331 99369
94816 96307
20242 42099
34808 39789
33113 41854
19216 75011
44653 79667
4828 67739
60972 73494
37992 67740
23614 49849
11691 82618
16394 36015
458 21161
73262 86791
74834 95175
19835 54462
8006 28373
1124 78212
2770 48378
82726 9994...

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 69ms
memory: 18276kb

input:

1
100000
91621 93237
56496 84023
12678 17780
4939 63181
17780 83963
5932 34844
17342 70763
32621 36332
39786 64960
41057 43821
23373 49059
35640 39497
10164 95487
26347 84688
36787 92392
27921 47871
32151 89476
27796 79323
11330 65453
47050 83175
39987 86560
20301 63715
3205 12554
76823 83863
83566 ...

output:

1

result:

ok single line: '1'

Test #20:

score: 0
Accepted
time: 64ms
memory: 18120kb

input:

1
100000
38291 85663
9914 70145
48001 56367
33806 56719
40530 48001
26580 62222
14966 92438
34168 35860
46259 56336
36794 72849
22639 34479
1051 9296
39260 85663
1742 34495
43275 58439
36666 91295
67177 91478
85687 89076
59546 78465
7875 75421
15706 55736
3369 92422
32097 42684
19305 60696
56935 923...

output:

1

result:

ok single line: '1'

Test #21:

score: 0
Accepted
time: 55ms
memory: 17824kb

input:

1
100000
38971 93416
9226 93416
22113 93416
31194 93416
92627 93416
7106 93416
93416 95225
22760 93416
1063 93416
12969 93416
80261 93416
93416 99593
16850 93416
35819 93416
66563 93416
54862 93416
57169 93416
34817 93416
60497 93416
13891 93416
80269 93416
48955 93416
14198 93416
70134 93416
59771 ...

output:

1

result:

ok single line: '1'

Test #22:

score: 0
Accepted
time: 70ms
memory: 17828kb

input:

1
100000
2354 27092
27092 67369
13923 27092
42165 90365
27092 52904
27092 34233
47738 90365
78327 90365
90365 91280
33611 90365
27092 35953
80700 90365
8069 27092
36892 90365
27092 90168
27092 33135
3005 90365
88375 90365
77402 90365
434 90365
38224 90365
27092 55431
1456 27092
50135 90365
22379 903...

output:

1

result:

ok single line: '1'

Test #23:

score: 0
Accepted
time: 65ms
memory: 17976kb

input:

1
100000
5265 17341
5265 56045
496 21643
26484 69016
16839 28871
16839 79781
21643 25661
21643 53429
16839 49697
2003 7145
16839 97239
69016 78113
2003 62670
5265 56740
21643 92645
5265 61255
50827 69016
21643 24229
21643 89959
69016 84181
2003 79923
21643 43043
7330 16839
21643 96020
16839 91196
52...

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 68ms
memory: 18420kb

input:

1
100000
10304 43215
10304 93394
30448 33451
18015 89885
22363 56611
56611 97015
39535 59758
57788 59758
61359 88426
9120 13565
56611 80671
18015 49699
35947 46370
34807 85262
3232 33451
10304 66020
18015 27347
36072 59758
39231 59758
18015 23271
9120 71111
33451 33807
36714 56611
1277 59758
75014 8...

output:

1

result:

ok single line: '1'

Test #25:

score: 0
Accepted
time: 60ms
memory: 18248kb

input:

1
100000
18569 94853
12294 29465
25783 64536
27350 39359
76660 79928
49183 92335
68841 77260
44573 61219
76911 93587
22187 28512
38363 52104
11784 33171
45225 74320
24733 58620
43423 81441
45212 62458
8960 86681
18119 89304
44032 72734
3113 44662
50644 82711
30392 57084
7249 79928
44825 56035
60202 ...

output:

1

result:

ok single line: '1'

Test #26:

score: 0
Accepted
time: 61ms
memory: 18448kb

input:

1
100000
1571 90468
91384 99150
32516 78851
42225 43818
25621 72220
21301 21374
33425 63678
23674 45780
28518 69993
5334 27380
8145 73762
21319 87035
20006 41357
66337 72244
12417 74478
39108 81052
41886 80085
41598 90469
37820 62641
14292 22292
23032 46380
3763 34157
41358 72220
67364 82979
17748 4...

output:

1

result:

ok single line: '1'

Test #27:

score: 0
Accepted
time: 93ms
memory: 20340kb

input:

1
100000
15732 84615
65478 72922
4812 70070
91545 99293
46477 59666
3314 93443
39531 64982
64747 82030
12281 98450
52745 57316
11751 17633
29601 84922
26662 71521
27947 71470
73449 97260
53282 87273
30913 32910
61053 92036
9316 35885
51360 77861
5693 14474
67875 86033
10664 32817
68257 80685
25788 3...

output:

0

result:

ok single line: '0'

Test #28:

score: 0
Accepted
time: 77ms
memory: 17900kb

input:

1
100000
39122 75849
42351 45694
64390 79652
20546 92407
58525 85387
2802 89047
55475 70767
35461 42042
28683 85597
50183 90609
79123 97504
7680 19455
8662 15318
2330 28664
21968 47791
26545 99256
35760 48583
67027 86346
49222 80976
39291 58154
84236 93936
50517 69137
18587 64139
20533 72118
32827 6...

output:

0

result:

ok single line: '0'

Test #29:

score: 0
Accepted
time: 56ms
memory: 18400kb

input:

1
100000
78403 94560
52684 62369
8991 28963
5240 33027
2410 80970
54998 99262
23309 24978
65969 88140
44628 46192
46032 82586
18739 30944
4149 49568
50909 75981
29053 72481
44017 68230
18598 95801
3095 37338
13292 20799
39164 41522
71361 89899
61456 87265
20034 76816
14457 91439
74116 75456
28178 60...

output:

0

result:

ok single line: '0'

Test #30:

score: 0
Accepted
time: 61ms
memory: 18360kb

input:

1
100000
23635 88992
19607 75823
31060 82008
63122 93848
22185 33690
32505 96800
33365 56049
24593 44623
25013 63810
8759 61190
57085 87064
53026 57349
45716 49352
9543 57438
3749 64110
1527 26497
6922 27142
9509 25979
36691 84730
48754 68947
18714 25054
65940 74195
15708 87136
22282 47301
4047 2520...

output:

0

result:

ok single line: '0'

Test #31:

score: 0
Accepted
time: 68ms
memory: 18292kb

input:

1
100000
18706 45356
35902 63739
85721 96649
19014 97560
30359 85721
30572 51003
54877 79877
15971 79156
65805 92693
86923 98325
41280 47502
42193 61041
25721 71038
7717 82469
69034 77566
28937 29157
77940 93752
24718 59410
10385 46565
2964 91347
16830 88383
71611 86158
77749 79935
32724 49030
86682...

output:

0

result:

ok single line: '0'

Test #32:

score: 0
Accepted
time: 67ms
memory: 18272kb

input:

1
100000
11560 77570
22569 86118
1609 62109
8355 44156
1609 55433
53411 68843
20315 69615
18947 93579
33758 68782
40591 62259
14651 70644
25253 84002
8763 11560
45932 65626
53202 58540
33417 89664
24846 97733
30290 73160
17504 44404
31385 96074
24068 60135
3849 58506
28973 88686
8533 75808
57680 928...

output:

0

result:

ok single line: '0'

Test #33:

score: 0
Accepted
time: 71ms
memory: 17796kb

input:

1
100000
74030 85908
28058 85908
85190 85908
81598 85908
21258 85908
15932 85908
83702 85908
85908 97272
67045 85908
10026 85908
28915 85908
85908 89229
60959 85908
5161 85908
85908 94442
14366 85908
71652 85908
85908 90855
4039 85908
25319 85908
54690 85908
58299 85908
85908 94091
81992 85908
85908...

output:

1

result:

ok single line: '1'

Test #34:

score: 0
Accepted
time: 88ms
memory: 17848kb

input:

1
100000
18667 64297
52888 64297
64297 75687
6968 74207
64297 92550
64297 88952
74207 76894
66629 74207
69216 74207
30077 74207
31476 64297
15420 74207
63765 64297
1699 74207
44612 64297
33271 64297
61396 74207
34063 74207
25669 74207
67751 74207
1781 74207
60880 64297
58646 64297
74207 84242
74207 ...

output:

1

result:

ok single line: '1'

Test #35:

score: 0
Accepted
time: 64ms
memory: 17928kb

input:

1
100000
14179 86021
44702 86021
51108 80516
12246 35793
1640 52100
1640 93897
51108 81182
36939 51108
1640 57834
24274 97817
1640 35715
35793 85695
24274 99014
49745 86021
51108 67726
80293 86021
33087 35793
44656 51108
51108 77213
35793 94902
24274 91373
51108 56358
1640 87187
684 51108
1640 71170...

output:

0

result:

ok single line: '0'

Test #36:

score: 0
Accepted
time: 72ms
memory: 18416kb

input:

1
100000
23091 55427
55378 55427
68503 93910
23737 97665
15203 67504
15203 41447
90608 99124
86454 99124
55261 64885
15689 26368
15203 37526
23737 97565
3516 62196
28818 42898
26105 93910
55427 56744
23737 70209
49133 99124
11002 99124
19973 23737
15689 85912
8966 93910
15203 17374
13220 99124
49535...

output:

0

result:

ok single line: '0'

Test #37:

score: 0
Accepted
time: 63ms
memory: 18264kb

input:

1
100000
59175 96860
1852 45606
22132 25840
25905 95716
23489 56400
43511 98158
63461 73870
46908 61418
18110 52202
17330 66950
17921 33738
67920 89483
16131 48115
45955 54882
2880 19244
27982 73539
90837 93180
17282 48083
33266 52410
266 17395
33056 73856
1407 99634
37758 56400
12973 61299
66732 89...

output:

0

result:

ok single line: '0'

Test #38:

score: 0
Accepted
time: 54ms
memory: 18552kb

input:

1
100000
50742 64794
37393 74158
67638 74283
40766 99219
970 91167
43159 85960
57043 85108
20289 72149
52254 57850
25965 77668
44308 62545
64771 82598
48506 68418
46600 66985
21768 29877
47015 96218
23873 83213
13194 81975
14653 49342
26730 50906
74093 77635
35958 53550
970 78239
72137 83538
37546 6...

output:

0

result:

ok single line: '0'

Test #39:

score: 0
Accepted
time: 34ms
memory: 7844kb

input:

10000
10
1 2
1 3
2 4
4 5
4 6
6 7
2 8
1 9
4 10
2
5
3
10
1
4
9
7
8
6
10
1 2
2 3
1 4
4 5
5 6
3 7
2 8
8 9
3 10
5
1
3
9
4
2
10
8
7
6
10
1 2
2 3
1 4
3 5
5 6
4 7
1 8
6 9
8 10
7
5
6
1
8
3
10
4
2
9
10
1 2
1 3
3 4
4 5
3 6
5 7
7 8
8 9
1 10
5
8
1
7
4
2
6
10
3
9
10
1 2
1 3
1 4
3 5
4 6
4 7
1 8
8 9
6 10
8
3
10
4
9...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
...

result:

ok 10000 lines

Test #40:

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

input:

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

output:

1
0

result:

ok 2 lines