QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#859782#9678. 网友小 Z 的树SunsetGlow9546 603ms46472kbC++141.4kb2025-01-17 23:27:332025-01-17 23:28:30

Judging History

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

  • [2025-01-17 23:28:30]
  • 评测
  • 测评结果:46
  • 用时:603ms
  • 内存:46472kb
  • [2025-01-17 23:27:33]
  • 提交

answer

#include "diameter.h"
#include <bits/stdc++.h>

std::mt19937 rnd(std::random_device{}());

int getfarthest(int x, int n) {
  using namespace std;
  int y(rnd() % (n - 1));
  if (y >= x) ++y;
  vector<vector<int>> ps(n);
  for (int i(0); i != n; ++i)
    if (i != x && i != y)
      ps[query(i + 1, x + 1, y + 1) / 2].push_back(i);
  int di(0);
  while (ps[di].empty()) ++di;
  int fd(di), fp(y);
  if (di == 2) {
//  cout << "check " << x << ' ' << y << endl;
    if (ps[2].size() == 1 && in(ps[2][0] + 1, x + 1, y + 1))
      y = ps[2][0];
    else
      --fd;
    --di;
  }
  while (di != 1) {
    y = ps[di][rnd() % ps[di].size()];
    for (int z : ps[di])
      if (z != y) ps[query(z + 1, x + 1, y + 1) / 2].push_back(z);
    while (!ps[di - 1].empty()) --di;
    if (di == 2) {
      if (ps[2].size() == 1 && in(ps[2][0] + 1, x + 1, y + 1))
        y = ps[2][0];
      --di;
    }
  }
  for (int d(fd-- + 1); d != n; ++d)
    for (int z : ps[d]) {
      int ths(query(z + 1, x + 1, y + 1) / 2);
      if (ths > fd) fd = ths, fp = z;
    }
//cout << x << ' ' << fp << ' ' << fd << ' ' << y << endl;
  return fp;
}

std::pair<int, int> find_diameter(int subid, int n) {
  using namespace std;
  if (n == 1) return {1, 1};
  if (n == 2) return {1, 2};
  int x(rnd() % n);
  int y(getfarthest(x, n));
  return {y + 1, getfarthest(y, n) + 1};
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 16
Accepted

Test #1:

score: 16
Accepted
time: 2ms
memory: 15476kb

input:

1 100
25
1 3
2 18
3 8
4 18
5 14
6 22
7 18
8 10
9 11
10 12
11 25
12 16
13 11
14 17
15 17
16 25
17 2
18 20
19 18
20 12
21 1
22 17
23 14
24 1
50
1 37
2 27
3 10
4 25
5 16
6 17
7 10
8 36
9 16
10 6
11 48
12 2
13 28
14 30
15 10
16 44
17 31
18 1
19 6
20 7
21 30
22 42
23 45
24 23
25 27
26 39
27 45
28 48
29 4...

output:

correct

result:

ok Correct

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 15
Accepted
time: 60ms
memory: 21864kb

input:

2 2006
42
1 32
2 4
3 6
4 29
5 1
6 42
7 10
8 16
9 6
10 25
11 42
12 8
13 36
14 8
15 17
16 3
17 6
18 21
19 23
20 31
21 42
22 6
23 32
24 7
25 27
26 34
27 31
28 6
29 41
30 20
31 9
32 7
33 3
34 5
35 5
36 1
37 8
38 14
39 15
40 12
41 22
95
1 94
2 88
3 13
4 71
5 37
6 45
7 87
8 24
9 76
10 54
11 69
12 95
13 90...

output:

correct

result:

ok Correct

Test #3:

score: 15
Accepted
time: 465ms
memory: 28032kb

input:

2 100
10000
5442 1084
1084 8984
8984 3299
3299 6385
6385 6079
6079 6806
6806 2300
2300 2996
2996 1765
1765 257
257 5537
5537 2337
2337 5445
5445 2873
2873 336
336 6307
6307 4968
4968 8078
8078 9944
9944 5675
5675 7896
7896 5943
5943 2412
2412 7448
7448 7852
7852 1684
1684 3437
3437 3980
3980 1919
19...

output:

correct

result:

ok Correct

Test #4:

score: 15
Accepted
time: 420ms
memory: 27344kb

input:

2 100
10000
1 5915
2 3020
3 9265
4 5171
5 1304
6 6769
7 1914
8 4904
9 7545
10 2296
11 4189
12 3509
13 7725
14 133
15 4023
16 7720
17 2707
18 9553
19 5215
20 6984
21 4421
22 2279
23 33
24 4737
25 4205
26 9619
27 1848
28 4322
29 5602
30 1476
31 2636
32 8841
33 3701
34 590
35 8382
36 9625
37 240
38 311...

output:

correct

result:

ok Correct

Test #5:

score: 15
Accepted
time: 441ms
memory: 27220kb

input:

2 100
10000
9186 8585
8585 2991
9186 2522
2991 2727
2991 3356
8585 7483
3356 6258
3356 3554
2727 9199
2991 6593
2727 3223
3223 780
2727 1306
7483 6018
3223 2570
7483 826
6258 7695
6593 303
9199 8280
8280 3057
3223 2719
1306 3966
7695 7382
3966 8835
8280 983
7382 5734
8280 3094
3057 4999
2719 5934
73...

output:

correct

result:

ok Correct

Test #6:

score: 15
Accepted
time: 439ms
memory: 29476kb

input:

2 100
10000
258 225
225 9405
9405 2228
225 912
258 2001
2001 7782
9405 2373
258 747
2001 7685
747 1101
7782 7229
2228 5458
2228 9451
9451 2073
2073 7753
5458 2328
7753 1592
1101 6637
2328 5359
1101 4393
4393 8882
1592 928
4393 9422
6637 2468
7753 3759
4393 6763
5359 8404
9422 7471
8882 7360
8404 184...

output:

correct

result:

ok Correct

Test #7:

score: 15
Accepted
time: 439ms
memory: 27416kb

input:

2 100
10000
5715 7993
5715 6965
7993 426
6965 2015
426 1744
2015 9193
426 4406
1744 7821
7821 4607
426 1151
7821 1378
4607 999
7821 5563
1744 8800
4607 3167
7821 4424
4406 6427
8800 2796
5563 8767
6427 2096
2796 659
659 7524
8800 39
4424 2158
8767 1736
2796 4824
659 2410
2096 8710
7524 2078
8710 119...

output:

correct

result:

ok Correct

Test #8:

score: 15
Accepted
time: 322ms
memory: 35572kb

input:

2 100
10000
475 1
475 2
475 3
475 4
475 5
475 6
475 7
475 8
475 9
475 10
475 11
475 12
475 13
475 14
475 15
475 16
475 17
475 18
475 19
475 20
475 21
475 22
475 23
475 24
475 25
475 26
475 27
475 28
475 29
475 30
475 31
475 32
475 33
475 34
475 35
475 36
475 37
475 38
475 39
475 40
475 41
475 42
475...

output:

correct

result:

ok Correct

Subtask #3:

score: 5
Accepted

Dependency #2:

100%
Accepted

Test #9:

score: 5
Accepted
time: 92ms
memory: 26932kb

input:

3 2006
95
1 50
2 83
3 65
4 31
5 64
6 83
7 22
8 17
9 12
10 24
11 81
12 82
13 70
14 71
15 16
16 66
17 68
18 25
19 64
20 90
21 19
22 14
23 4
24 55
25 11
26 15
27 47
28 90
29 33
30 10
31 73
32 4
33 32
34 13
35 46
36 42
37 36
38 17
39 47
40 67
41 23
42 72
43 75
44 92
45 57
46 88
47 78
48 43
49 58
50 62
5...

output:

correct

result:

ok Correct

Test #10:

score: 5
Accepted
time: 562ms
memory: 33848kb

input:

3 50
20000
12483 13249
13249 6419
6419 18097
18097 17847
17847 2932
2932 14960
14960 6371
6371 3371
3371 18403
18403 18882
18882 16513
16513 13330
13330 7685
7685 2725
2725 9445
9445 10962
10962 6952
6952 5108
5108 12657
12657 4299
4299 9621
9621 4521
4521 16644
16644 14790
14790 15234
15234 13858
1...

output:

correct

result:

ok Correct

Test #11:

score: 5
Accepted
time: 487ms
memory: 32152kb

input:

3 50
20000
1 10511
2 8258
3 11981
4 12921
5 14758
6 443
7 5500
8 4105
9 15921
10 19586
11 6477
12 14217
13 9381
14 10767
15 6566
16 3232
17 18904
18 15280
19 17754
20 1743
21 994
22 16695
23 13403
24 2947
25 14089
26 19962
27 12998
28 4014
29 8751
30 8029
31 14686
32 8019
33 13808
34 852
35 2992
36 ...

output:

correct

result:

ok Correct

Test #12:

score: 5
Accepted
time: 503ms
memory: 32236kb

input:

3 50
20000
14783 6405
14783 997
14783 15183
6405 4079
14783 3959
6405 13688
13688 394
6405 18458
997 2652
2652 8182
6405 8855
13688 13569
3959 9652
18458 19932
3959 2233
13688 2925
2925 17109
9652 520
2652 3931
2925 12446
2233 17300
520 11989
17300 14352
17300 1490
14352 17585
17109 15867
3931 7306
...

output:

correct

result:

ok Correct

Test #13:

score: 5
Accepted
time: 502ms
memory: 32408kb

input:

3 50
20000
5219 5072
5072 18451
5219 1483
5219 6164
6164 11035
1483 9913
9913 10220
6164 6063
6164 2560
1483 987
6164 16481
16481 13784
6063 485
10220 11717
2560 16335
6063 19981
987 6387
13784 14504
2560 14762
16481 11230
13784 13201
14504 9437
14762 19951
6387 7610
16335 1501
9437 14901
9437 13391...

output:

correct

result:

ok Correct

Test #14:

score: 5
Accepted
time: 494ms
memory: 30380kb

input:

3 50
20000
11410 9893
11410 2259
11410 13823
2259 14136
9893 18639
2259 5699
9893 13085
9893 13095
2259 4627
5699 5572
13823 12950
13823 17350
12950 12984
4627 14584
5572 9511
13095 18547
17350 13655
17350 11614
14584 17057
5572 1023
13655 3546
17057 8142
1023 2641
17057 13187
13655 10323
11614 1419...

output:

correct

result:

ok Correct

Test #15:

score: 5
Accepted
time: 350ms
memory: 38228kb

input:

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

output:

correct

result:

ok Correct

Subtask #4:

score: 5
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 5
Accepted
time: 123ms
memory: 32768kb

input:

4 2006
72
1 11
2 33
3 63
4 45
5 70
6 23
7 41
8 51
9 63
10 71
11 56
12 36
13 55
14 1
15 45
16 68
17 37
18 65
19 1
20 42
21 16
22 27
23 1
24 14
25 4
26 13
27 52
28 34
29 28
30 72
31 43
32 13
33 47
34 6
35 26
36 69
37 16
38 9
39 47
40 6
41 10
42 50
43 28
44 9
45 35
46 28
47 51
48 68
49 59
50 26
51 10
5...

output:

correct

result:

ok Correct

Test #17:

score: 5
Accepted
time: 578ms
memory: 39508kb

input:

4 33
30000
14256 19392
19392 17693
17693 12064
12064 29690
29690 2629
2629 2231
2231 8291
8291 20777
20777 13056
13056 17592
17592 3521
3521 9564
9564 20486
20486 11910
11910 5841
5841 8074
8074 8949
8949 27794
27794 5140
5140 628
628 23696
23696 219
219 27931
27931 12329
12329 11380
11380 16340
163...

output:

correct

result:

ok Correct

Test #18:

score: 5
Accepted
time: 489ms
memory: 34916kb

input:

4 33
30000
1 10055
2 15066
3 26132
4 2602
5 25450
6 3181
7 10378
8 16011
9 14843
10 5467
11 23120
12 20330
13 4410
14 24149
15 1259
16 25325
17 5148
18 22993
19 14548
20 17083
21 21423
22 4431
23 2608
24 27414
25 7398
26 680
27 6389
28 7789
29 24276
30 23976
31 21652
32 14331
33 4244
34 2538
35 1511...

output:

correct

result:

ok Correct

Test #19:

score: 5
Accepted
time: 511ms
memory: 35184kb

input:

4 33
30000
5160 22570
5160 4162
22570 4564
22570 2953
22570 6160
2953 16958
5160 18469
18469 16390
4564 4820
4820 26260
4820 23921
4820 22416
16390 5064
18469 21384
4820 18969
22416 2213
18469 10791
23921 18801
2213 28618
23921 12934
12934 23199
2213 2731
23199 13937
18801 7907
18969 12659
2213 1006...

output:

correct

result:

ok Correct

Test #20:

score: 5
Accepted
time: 504ms
memory: 35280kb

input:

4 33
30000
5124 14169
14169 7693
14169 3148
7693 7827
7827 5425
14169 4462
7693 5036
7827 1840
5036 15358
3148 354
15358 25457
354 23612
5036 809
15358 28504
15358 220
28504 12793
1840 25908
354 240
25908 14658
354 12184
23612 25257
14658 26851
809 10856
12184 23643
14658 23748
23643 7400
7400 19133...

output:

correct

result:

ok Correct

Test #21:

score: 5
Accepted
time: 517ms
memory: 35188kb

input:

4 33
30000
16458 22215
22215 25117
16458 10098
16458 19468
19468 19780
22215 18948
25117 1930
10098 601
22215 28765
1930 28418
25117 12818
10098 29737
29737 8189
12818 2531
28765 23263
12818 20088
20088 3660
28765 3752
29737 2048
3752 10286
20088 14216
20088 5154
3752 12129
2531 5116
3660 12518
5116...

output:

correct

result:

ok Correct

Test #22:

score: 5
Accepted
time: 350ms
memory: 40508kb

input:

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

output:

correct

result:

ok Correct

Subtask #5:

score: 5
Accepted

Dependency #4:

100%
Accepted

Test #23:

score: 5
Accepted
time: 164ms
memory: 38704kb

input:

5 2006
74
1 63
2 63
3 55
4 35
5 36
6 63
7 64
8 71
9 61
10 47
11 18
12 62
13 41
14 59
15 70
16 27
17 5
18 30
19 59
20 65
21 28
22 41
23 18
24 20
25 14
26 4
27 63
28 17
29 37
30 49
31 7
32 64
33 2
34 7
35 32
36 22
37 7
38 26
39 46
40 18
41 37
42 73
43 19
44 53
45 15
46 20
47 53
48 63
49 10
50 15
51 15...

output:

correct

result:

ok Correct

Test #24:

score: 5
Accepted
time: 603ms
memory: 42888kb

input:

5 25
40000
9770 7780
7780 34738
34738 37985
37985 15685
15685 21772
21772 1975
1975 582
582 26341
26341 13165
13165 34397
34397 39627
39627 34769
34769 18282
18282 23951
23951 34185
34185 15227
15227 28159
28159 1721
1721 17784
17784 36525
36525 38137
38137 29531
29531 22379
22379 36276
36276 3637
3...

output:

correct

result:

ok Correct

Test #25:

score: 5
Accepted
time: 522ms
memory: 39608kb

input:

5 25
40000
1 19786
2 20270
3 26558
4 308
5 18939
6 28114
7 29876
8 25726
9 8597
10 26654
11 19829
12 1028
13 4133
14 4851
15 26521
16 29163
17 310
18 27981
19 19834
20 27717
21 30635
22 24263
23 20478
24 7257
25 3035
26 20922
27 17446
28 39771
29 3904
30 11759
31 18587
32 20761
33 12342
34 27898
35 ...

output:

correct

result:

ok Correct

Test #26:

score: 5
Accepted
time: 539ms
memory: 40036kb

input:

5 25
40000
36764 35314
36764 37104
36764 12118
35314 32376
37104 22392
22392 24470
32376 23023
23023 34964
37104 39669
22392 32311
22392 31856
32311 9326
31856 16319
23023 10898
31856 31172
10898 26464
31856 22435
34964 5426
32311 10612
22435 1868
10612 433
10898 6371
10612 27937
6371 10091
5426 274...

output:

correct

result:

ok Correct

Test #27:

score: 5
Accepted
time: 563ms
memory: 39920kb

input:

5 25
40000
10000 5625
5625 14082
14082 34314
34314 29412
14082 38558
29412 35886
35886 31474
5625 22366
35886 33342
22366 12865
38558 13915
35886 4966
29412 3655
33342 20958
13915 23834
4966 7351
20958 24278
3655 10661
4966 32288
12865 12551
32288 37871
32288 37180
20958 4257
32288 37808
24278 39254...

output:

correct

result:

ok Correct

Test #28:

score: 5
Accepted
time: 549ms
memory: 37916kb

input:

5 25
40000
27638 17632
17632 35387
35387 24098
35387 13326
24098 28923
13326 7854
24098 22355
13326 12236
35387 30495
24098 5269
24098 12357
28923 18620
22355 31349
28923 17802
30495 6723
22355 20054
17802 4285
18620 5098
20054 609
18620 17874
4285 19437
31349 30277
31349 32994
30277 23651
19437 283...

output:

correct

result:

ok Correct

Test #29:

score: 5
Accepted
time: 371ms
memory: 45684kb

input:

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

output:

correct

result:

ok Correct

Subtask #6:

score: 0
Wrong Answer

Dependency #5:

100%
Accepted

Test #30:

score: 10
Accepted
time: 191ms
memory: 44144kb

input:

6 2006
79
1 62
2 71
3 52
4 23
5 22
6 12
7 65
8 32
9 45
10 67
11 48
12 37
13 67
14 8
15 43
16 65
17 37
18 55
19 47
20 55
21 6
22 23
23 71
24 54
25 10
26 22
27 70
28 56
29 27
30 74
31 37
32 65
33 7
34 26
35 63
36 13
37 22
38 40
39 50
40 19
41 72
42 79
43 76
44 51
45 27
46 17
47 53
48 47
49 63
50 16
51...

output:

correct

result:

ok Correct

Test #31:

score: 0
Wrong Answer
time: 351ms
memory: 46472kb

input:

6 20
50000
3285 10412
10412 43006
43006 155
155 17821
17821 32499
32499 10047
10047 12804
12804 41225
41225 39582
39582 25546
25546 39164
39164 31225
31225 6444
6444 27823
27823 48791
48791 29070
29070 9568
9568 25857
25857 21241
21241 43335
43335 6900
6900 26523
26523 43337
43337 21557
21557 6101
6...

output:

WA

result:

wrong answer Wrong Answer

Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #7:

0%

Subtask #9:

score: 0
Skipped

Dependency #8:

0%

Subtask #10:

score: 0
Skipped

Dependency #9:

0%

Subtask #11:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

0%