QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#860400#9678. 网友小 Z 的树Physics21230331 369ms31220kbC++171.2kb2025-01-18 13:12:272025-01-18 13:13:29

Judging History

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

  • [2025-01-18 13:13:29]
  • 评测
  • 测评结果:31
  • 用时:369ms
  • 内存:31220kb
  • [2025-01-18 13:12:27]
  • 提交

answer

#include "diameter.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
mt19937 g(time(0));
pii find_diameter(int id,int n){
  if(n==1)return make_pair(1,1);
  if(n==2)return make_pair(1,2);
  vector<int> p(n);
  iota(p.begin(),p.end(),1);
  shuffle(p.begin(),p.end(),g);
  uniform_int_distribution<> U(1,n);
  int u=U(g),v=U(g),w=U(g);
  while(v==u)v=U(g);
  while(w==u||w==v)w=U(g);
  int c=query(u,v,w);
  for(int i=0;i<(n<=50?p.size():p.size()>>2);i++)
    if(p[i]!=u&&p[i]!=v&&p[i]!=w){
      int r1=query(u,v,p[i]),r2=query(u,w,p[i]);
      if(c=min({c,r1,r2});c==r1)w=p[i];
      else if(c==r2)v=p[i];
    }
  if(in(u,w,v))swap(u,w);
  u=c=0;
  for(int i=1;i<=n;i++)
    if(i!=v&&i!=w){
      int r=query(v,w,i);
      if(r>c)c=r,u=i;
    }
  v=U(g),w=U(g);
  while(v==u)v=U(g);
  while(w==u||w==v)w=U(g);
  c=query(u,v,w);
  for(int i=0;i<(n<=50?p.size():p.size()>>2);i++)
    if(p[i]!=u&&p[i]!=v&&p[i]!=w){
      int r1=query(u,v,p[i]),r2=query(u,w,p[i]);
      if(c=min({c,r1,r2});c==r1)w=p[i];
      else if(c==r2)v=p[i];
    }
  if(in(w,u,v))swap(w,v);
  w=c=0;
  for(int i=1;i<=n;i++)
    if(i!=u&&i!=v){
      int r=query(u,v,i);
      if(r>c)c=r,w=i;
    }
  return make_pair(u,w);
}

詳細信息

Subtask #1:

score: 16
Accepted

Test #1:

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

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: 49ms
memory: 21336kb

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: 331ms
memory: 27396kb

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: 368ms
memory: 27092kb

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: 358ms
memory: 27104kb

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: 357ms
memory: 27012kb

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: 369ms
memory: 27052kb

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: 321ms
memory: 31220kb

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: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #9:

score: 0
Wrong Answer
time: 31ms
memory: 17576kb

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:

WA

result:

wrong answer Wrong Answer

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

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:

0%