QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22368#1757. Grand Central Stationjyyyyds#AC ✓575ms32816kbC++20856b2022-03-09 16:28:312022-04-30 00:57: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-30 00:57:57]
  • 评测
  • 测评结果:AC
  • 用时:575ms
  • 内存:32816kb
  • [2022-03-09 16:28:31]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
#define N 300005

std::mt19937_64 rng(58);

int n;
std::vector<int> E[N];

ull hsh[N];

int sz[N];
ull f[N];
inline void dfs1(int u,int fa){
	sz[u]=1;
	f[u]=0;
	for(auto v:E[u]) if(v!=fa){
		dfs1(v,u);
		sz[u]+=sz[v];
		f[u]+=f[v]^hsh[sz[v]];
	}
}
ull g[N];
inline void dfs2(int u,int fa){
	for(auto v:E[u]) if(v!=fa){
		g[v]=(g[u]+f[u]-(f[v]^hsh[sz[v]]))^hsh[n-sz[v]];
		dfs2(v,u);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		E[u].push_back(v),E[v].push_back(u);
	}
	int ans=0;
	for(int o=0;o<5;o++){
		for(int i=1;i<=n;i++)
			hsh[i]=rng();
		dfs1(1,0),dfs2(1,0);
		std::unordered_set<ull> s;
		for(int i=1;i<=n;i++)
			s.insert(f[i]+g[i]);
		ans=std::max(ans,(int)s.size());
	}
	printf("%d\n",ans);
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 10984kb

input:

1000
438 102
97 433
728 280
620 314
120 43
834 500
374 154
556 182
542 265
711 870
952 273
104 76
109 549
73 871
65 861
649 731
679 547
306 987
109 583
776 295
37 936
836 362
247 700
967 811
817 995
482 818
34 324
763 591
12 515
890 599
756 243
503 941
265 332
408 790
274 799
448 282
733 363
424 274...

output:

784

result:

ok single line: '784'

Test #2:

score: 0
Accepted
time: 2ms
memory: 10896kb

input:

1000
21 386
710 824
505 123
943 634
624 718
40 230
652 634
448 794
858 767
566 176
535 944
38 563
866 943
415 68
597 127
649 70
318 980
79 353
831 876
55 357
679 104
427 951
736 669
129 29
813 405
879 160
99 973
73 699
202 700
565 80
11 477
521 315
464 132
560 304
351 555
671 949
571 393
273 730
881...

output:

828

result:

ok single line: '828'

Test #3:

score: 0
Accepted
time: 47ms
memory: 14636kb

input:

38558
7003 23985
29307 29351
703 34035
30888 32096
30611 37877
1772 19028
8792 15844
28451 25209
27875 32487
22935 260
38261 22356
32425 35251
18290 23963
30763 31440
4689 20025
9076 37955
8185 17786
29703 28208
25142 26831
32543 25661
23763 30430
5261 25175
26576 22388
12988 12555
11220 24674
36527...

output:

38505

result:

ok single line: '38505'

Test #4:

score: 0
Accepted
time: 557ms
memory: 29220kb

input:

288354
232840 117312
162741 262522
279350 119278
10580 162741
73466 217320
179730 91475
86898 105936
281878 17577
121709 262578
98208 275496
143650 27167
234538 248941
92384 247459
104666 26510
172704 118571
271484 235172
284116 135213
115626 85372
195358 63709
270389 108426
132939 109287
250658 250...

output:

20984

result:

ok single line: '20984'

Test #5:

score: 0
Accepted
time: 199ms
memory: 21324kb

input:

95504
56881 88368
31237 22349
83053 4113
94662 74197
24572 60632
23472 20345
8246 29223
23161 8866
25614 84614
60063 73627
58372 46167
70693 37240
77485 40459
33403 37917
21426 70251
57562 16829
73827 66275
54331 61513
13503 68175
9671 61761
70917 52865
40374 64238
14471 5991
38004 68517
46785 68336...

output:

95373

result:

ok single line: '95373'

Test #6:

score: 0
Accepted
time: 14ms
memory: 11332kb

input:

3871
342 2313
2012 2027
2233 1840
3114 2620
3031 2284
871 1366
2037 3761
558 1370
2425 2794
1564 2478
435 1458
1066 1224
1894 1469
2856 253
696 3126
116 166
1901 15
1899 2224
834 2326
2970 2123
3595 398
2947 1780
1331 3348
2964 3679
1247 3590
3036 1128
2380 2739
1125 372
2663 1600
1812 2904
2770 190...

output:

3871

result:

ok single line: '3871'

Test #7:

score: 0
Accepted
time: 3ms
memory: 11064kb

input:

1469
1365 900
84 740
110 616
476 39
188 1194
1003 563
1058 325
531 866
1412 843
1162 1419
83 300
568 1174
911 69
58 611
1160 452
918 343
701 430
910 665
961 175
1213 752
414 334
811 474
421 9
385 1416
81 1116
159 694
820 792
379 1034
989 421
1302 840
511 685
781 422
228 893
1394 334
1082 972
1297 18...

output:

1469

result:

ok single line: '1469'

Test #8:

score: 0
Accepted
time: 575ms
memory: 31336kb

input:

175819
11277 113133
12609 95478
100262 100323
77490 39122
109858 16865
80865 142912
110636 48853
125281 136378
42758 12882
23846 32461
116890 33708
37129 65240
47518 165507
14820 164754
125913 159493
122149 47528
144074 13845
115620 46748
137806 7032
7542 63258
165381 72402
144152 119110
105231 3797...

output:

175267

result:

ok single line: '175267'

Test #9:

score: 0
Accepted
time: 3ms
memory: 10852kb

input:

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

output:

20

result:

ok single line: '20'

Test #10:

score: 0
Accepted
time: 7ms
memory: 10892kb

input:

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

output:

10

result:

ok single line: '10'

Test #11:

score: 0
Accepted
time: 242ms
memory: 29120kb

input:

300000
292135 15478
15478 136216
109185 15478
15478 242099
103220 103279
15478 22455
15478 102679
5604 15478
76086 103220
103220 208942
15478 179342
210978 15478
15478 115167
226522 15478
103220 209365
203552 103220
15478 235035
140119 15478
15478 249837
123062 103220
223686 15478
112203 15478
50845...

output:

2

result:

ok single line: '2'

Test #12:

score: 0
Accepted
time: 228ms
memory: 21964kb

input:

105794
76736 23390
93047 40011
46085 17858
95620 30454
72606 69064
81548 71375
89542 73664
66524 67299
7647 37844
58361 76223
77613 63623
83909 44822
68359 98225
1350 97362
67436 17260
73270 63852
52184 92453
719 36806
55855 22342
32085 36008
31772 17244
53334 39479
1098 81068
40235 33878
63798 4852...

output:

103031

result:

ok single line: '103031'

Test #13:

score: 0
Accepted
time: 564ms
memory: 32816kb

input:

276262
2946 75329
127924 249904
115653 154386
76098 136172
45205 262808
261950 65566
18564 90926
260195 97193
97843 190276
242702 153221
42507 191412
45653 73382
249361 117669
22884 217604
47983 262738
26356 6176
191734 82159
195561 61976
125595 97194
194242 149567
189389 186398
241528 54030
231489 ...

output:

108544

result:

ok single line: '108544'

Test #14:

score: 0
Accepted
time: 569ms
memory: 31400kb

input:

299619
218764 98442
206412 273853
26899 128877
109578 92945
287118 149372
253286 208830
263011 189024
226852 287954
101914 175066
297949 234307
93690 62374
170820 40304
148307 254782
23602 175276
33924 250988
179658 296711
29715 177000
229224 698
77108 200321
281241 210349
70706 238979
26453 37795
5...

output:

55663

result:

ok single line: '55663'

Test #15:

score: 0
Accepted
time: 511ms
memory: 29316kb

input:

298742
133751 176370
275294 156008
122306 209897
234377 197029
215464 212287
176520 210432
279094 280632
56085 280381
28133 197004
188123 129079
1275 265657
249362 185370
192548 246821
219928 278817
92546 286425
208499 15773
232775 46298
210432 14577
191251 197715
49602 164705
31992 105104
269294 25...

output:

5521

result:

ok single line: '5521'

Test #16:

score: 0
Accepted
time: 0ms
memory: 10964kb

input:

1000
39 652
523 560
749 120
297 37
571 685
337 882
78 870
561 438
947 123
814 964
280 75
534 314
942 928
916 494
813 644
914 249
789 356
462 366
93 472
221 243
741 168
683 103
207 963
537 573
522 967
909 578
738 631
52 327
772 935
422 472
216 665
689 837
617 973
90 896
894 80
308 822
162 102
164 281...

output:

801

result:

ok single line: '801'