QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866001#9678. 网友小 Z 的树masterhuang31 464ms28564kbC++231.5kb2025-01-22 10:29:032025-01-22 10:29:05

Judging History

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

  • [2025-01-22 10:29:05]
  • 评测
  • 测评结果:31
  • 用时:464ms
  • 内存:28564kb
  • [2025-01-22 10:29:03]
  • 提交

answer

#include "diameter.h"
#include <bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
mt19937 rnd(time(0));
const int N=1e5+5,inf=1e9,U=100;
int n,f[N],p[N];bool ban[N];
inline void R()
{
	if(n<=1e4) return;
	shuffle(p+1,p+1+n,rnd);fill(ban+1,ban+1+n,0);
	for(int i=1;i<=min(n,U<<1);i++) ban[p[i]]=1;
}
P find_diameter(int id,int n)
{
	::n=n;if(n==1) return {1,1};
	if(n==2) return {1,2};
	if(n==3)
	{
		bool o1=in(1,2,3),o2=in(2,1,3);
		if(o1) return {2,3};
		if(o2) return {1,3};return {1,2};
	}fill(f+1,f+1+n,inf+1);iota(p+1,p+1+n,1);
	int x=1,y=2,z=3,d=query(1,2,3),mn=inf;R();
	for(int i=1;i<=n;i++) if(i!=y&&i!=z&&!ban[i])
	{
		int D=query(i,y,z);
		if(D>d) d=D,x=i;
	}
	for(int i=1;i<=n;i++) if(i!=x&&i!=z)
	{
		int D=query(x,i,z);
		if(D>d) d=D,y=i;
	}
	for(int i=1;i<=n;i++) if(i!=x&&i!=y)
	{
		int D=query(x,y,i);mn=min(mn,f[i]=D);
		if(D>d) d=D,z=i;
	}
	if(f[z]==mn) return {x,y};
	bool o1=in(x,y,z),o2=in(y,x,z);
	if(o1) return {y,z};if(o2) return {x,z};
	vector<int>g;int d1=mn,d2=inf,d3=inf,mx,c2=1,c3=1;
	for(int i=1;i<=n;i++) if(f[i]==mn) g.push_back(i);
	shuffle(g.begin(),g.end(),rnd);
	for(int i=0;i<min((int)g.size(),U);i++)
	{
		int n2=query(x,z,g[i]),n3=query(y,z,g[i]);
		c2+=(n2==d2);c3+=(n3==d3);
		if(n2<d2) c2=1,d2=n2;if(n3<d3) c3=1,d3=n3;
	}
	if(g.size()>U){if(c2<=5) d2=-1;if(c3<=5) d3=-1;}
	mx=max({d1,d2,d3});
	if(d1==mx) return {x,y};
	if(d2==mx) return {x,z};return {y,z};
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 16
Accepted

Test #1:

score: 16
Accepted
time: 1ms
memory: 8144kb

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: 47ms
memory: 20120kb

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: 347ms
memory: 25796kb

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: 391ms
memory: 25824kb

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: 371ms
memory: 24068kb

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: 372ms
memory: 22668kb

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: 376ms
memory: 25556kb

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: 292ms
memory: 28168kb

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: 5
Accepted
time: 83ms
memory: 23084kb

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: 434ms
memory: 26692kb

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: 464ms
memory: 28564kb

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: 0
Wrong Answer
time: 135ms
memory: 27340kb

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:

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%