QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369031#7791. 通道建设 Passage ConstructionNATURAL611 16ms6140kbC++174.3kb2024-03-27 19:41:482024-03-27 19:41:50

Judging History

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

  • [2024-03-27 19:41:50]
  • 评测
  • 测评结果:11
  • 用时:16ms
  • 内存:6140kb
  • [2024-03-27 19:41:48]
  • 提交

answer

#include <bits/stdc++.h>
#include "passageconstruction.h"
using namespace std;
int n,dep[10010],mdep,dfn[10010],tot,fa[14][10010],siz[20010];
int node_siz,edge_siz,id[10010],nowdep,vis[20010],msiz,eid,eU,eV;
vector<int>S[10010],e[10010],E[10010],lst;
vector< pair<int,int> >ans,se[20010];
inline void adde(int x,int y)
{
	e[x].emplace_back(y);
	fa[0][y]=x;
	for(int i=1;i<14;++i)fa[i][y]=fa[i-1][fa[i-1][y]];
	return ;
}
inline int get_lca(int x,int y)
{
	if(x==y)return x;
	if(dep[x]<dep[y])swap(x,y);
	for(int i=13;~i;--i)while(dep[fa[i][x]]>=dep[y])x=fa[i][x];
	if(x==y)return x;
	for(int i=13;~i;--i)while(fa[i][x]^fa[i][y])x=fa[i][x],y=fa[i][y];
	return fa[0][x];
}
inline void dfs(int rt)//求 dfs 序
{
	dfn[rt]=++tot;
	for(int i:e[rt])dfs(i);
	return ;
}
inline bool cmp(int x,int y){return dfn[x]<dfn[y];}
inline int build(vector<int>S)
{
	sort(S.begin(),S.end(),cmp);
	for(int i=(int)S.size()-1;i;--i)S.emplace_back(get_lca(S[i],S[i-1]));
	sort(S.begin(),S.end(),cmp);S.resize(unique(S.begin(),S.end())-S.begin());
	for(int i=1;i<(int)S.size();++i)E[get_lca(S[i],S[i-1])].emplace_back(S[i]);
	lst=S;
	return S[0];
}
inline int dfss(int rt,int da)// 三度化
{
	if(E[rt].empty())return id[++node_siz]=rt,node_siz;
	if(E[rt].size()==1)
	{
		int U=++node_siz,V=dfss(E[rt][0],rt);
		id[U]=rt;++edge_siz;
		se[U].emplace_back(make_pair(V,edge_siz));
		se[V].emplace_back(make_pair(U,edge_siz));
		return U;
	}
	else
	{
		int V=dfss(E[rt].back(),rt);
		for(int i=E[rt].size()-2;~i;--i)
		{
			int rot=++node_siz,U=dfss(E[rt][i],rt);
			++edge_siz;
			se[rot].emplace_back(make_pair(U,edge_siz));
			se[U].emplace_back(make_pair(rot,edge_siz));
			++edge_siz;
			se[rot].emplace_back(make_pair(V,edge_siz));
			se[V].emplace_back(make_pair(rot,edge_siz));
			V=rot;id[rot]=rt;
		}
		return V;
	}
	return 0;
}
inline int get_id(int rt,int da)
{
	if(dep[id[rt]]==nowdep)return id[rt];
	for(pair<int,int>i:se[rt])
	{
		if(i.first==da||vis[i.second])continue;
		return get_id(i.first,rt);
	}
	return 0;
}
inline void findroot(int rt,int da,int SZ)
{
	if(dep[id[rt]]==nowdep)siz[rt]=1;
	else siz[rt]=0;
	for(pair<int,int>i:se[rt])
	{
		if(i.first==da||vis[i.second])continue;
		findroot(i.first,rt,SZ);siz[rt]+=siz[i.first];
		if(msiz>max(siz[i.first],SZ-siz[i.first]))msiz=max(siz[i.first],SZ-siz[i.first]),eU=rt,eV=i.first,eid=i.second;
	}
	return ;
}
inline int dfssss(int rt,int da)// 求 siz
{
	int an=(dep[id[rt]]==nowdep);
	for(pair<int,int>i:se[rt])
	{
		if(i.first==da||vis[i.second])continue;
		an+=dfssss(i.first,rt);
	}
	return an;
}
inline void dfsssss(int rt,int da,vector<int>&S,int rot)// 求点集
{
	if(id[rt]^rot)return S.emplace_back(id[rt]),void();
	for(pair<int,int>i:se[rt])
	{
		if(i.first==da||vis[i.second])continue;
		dfsssss(i.first,rt,S,rot);
	}
	return ;
}
inline void dfz(int rt,int SZ,vector<int>nodeset)
{
	if(!SZ||nodeset.empty())return ;
	if(SZ==1)
	{
		int ID=get_id(rt,0);
		for(int i:nodeset)adde(ID,i);
		return ;
	}
	msiz=SZ+1;
	findroot(rt,0,SZ);
	vector<int>res,B,toU,toV;B.emplace_back(id[eU]);
	dfsssss(eV,eU,B,id[eU]);
	int sizU=dfssss(eU,eV),sizV=dfssss(eV,eU);
	vis[eid]=1;
	if(B.size()==1)res.resize(nodeset.size(),1);
	else res=QueryLCA(nodeset,B,id[eU]);
	for(int i=0;i<(int)nodeset.size();++i)
	{
		if(res[i])toU.emplace_back(nodeset[i]);
		else toV.emplace_back(nodeset[i]);
	}
	int eeU=eU,eeV=eV;
	dfz(eeU,sizU,toU);dfz(eeV,sizV,toV);
	return ;
}
inline void solve(int D)
{
	for(int i:lst)E[i].clear();
	for(int i=1;i<=node_siz;++i)se[i].clear();
	memset(vis,0,(edge_siz+1)<<2);
	node_siz=edge_siz=0;nowdep=D-1;
	int rot=build(S[D-1]);
	rot=dfss(rot,0);
	dfz(rot,node_siz,S[D]);
	tot=0;dfs(1);
	return ;
}
inline int dfsss(int rt)// 求匹配
{
	int son=0;
	for(int i:e[rt])
	{
		int p=dfsss(i);
		if(p)
		{
			if(son)
			{
				ans.emplace_back(make_pair(p,son));
				son=0;
			}
			else son=p;
		}
	}
	if(son)
	{
		ans.emplace_back(make_pair(rt,son));
		son=0;
	}
	else son=rt;
	return son;
}
vector< pair<int,int> >ConstructPassages(int N,const vector< pair<int,int> >&E)
{
	n=N;dep[0]=-1;
	for(int i=2;i<=(n<<1);++i)
	{
		S[dep[i]=GetDistance(1,i)].emplace_back(i);
		mdep=max(mdep,dep[i]);
	}
	S[0].emplace_back(1);dfn[1]=tot=1;
	for(int i=1;i<=mdep;++i)solve(i);
	dfsss(1);
	return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 1ms
memory: 6008kb

input:

1
1872884041
100 100 10000 10000
1
2294931821 2294931820

output:

Succeeded
0 1 0 0
1 2

result:

ok Accepted with 0+1 operations,sum of size(s)=0+0

Test #2:

score: 3
Accepted
time: 1ms
memory: 5192kb

input:

1
1977600624
100 100 10000 10000
5
621522394 621522399
2231003352 2231003338
464307841 464307837
1851407771 1851407768
2780336863 2780336849
314073909 314073902
1173467454 1173467430
4215033871 4215033843
2620057116 2620057098

output:

Succeeded
5 9 11 11
7 4
6 2
3 8
5 9
1 10

result:

ok Accepted with 5+9 operations,sum of size(s)=11+11

Test #3:

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

input:

1
1314992723
100 100 10000 10000
2
1174248192 1174248188
4206147071 4206147069
2894997654 2894997645

output:

Succeeded
0 3 0 0
2 4
1 3

result:

ok Accepted with 0+3 operations,sum of size(s)=0+0

Test #4:

score: 3
Accepted
time: 1ms
memory: 5204kb

input:

1
1466488642
100 100 10000 10000
3
1959342134 1959342129
3976386946 3976386946
1293201451 1293201449
4016912388 4016912383
46728190 46728181

output:

Succeeded
1 5 1 2
2 3
6 4
1 5

result:

ok Accepted with 1+5 operations,sum of size(s)=1+2

Test #5:

score: 3
Accepted
time: 1ms
memory: 5248kb

input:

1
1733551538
100 100 10000 10000
4
4255320958 4255320951
1233889267 1233889267
2022156010 2022156014
1746602236 1746602223
1796304111 1796304099
154520793 154520786
799267407 799267389

output:

Succeeded
2 7 3 4
2 5
3 7
4 8
1 6

result:

ok Accepted with 2+7 operations,sum of size(s)=3+4

Test #6:

score: 3
Accepted
time: 1ms
memory: 5200kb

input:

1
1103590331
100 100 10000 10000
4
3735090189 3735090176
179620503 179620501
1550955883 1550955882
3533004575 3533004552
2159969243 2159969227
2549716219 2549716202
1755562372 1755562356

output:

Succeeded
2 7 3 4
5 6
8 7
4 2
1 3

result:

ok Accepted with 2+7 operations,sum of size(s)=3+4

Test #7:

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

input:

1
1007922703
100 100 10000 10000
5
3347355425 3347355424
924935451 924935434
3554593528 3554593525
2830078883 2830078872
3185621515 3185621508
32902500 32902483
1057526055 1057526035
3737430162 3737430144
106424402 106424399

output:

Succeeded
4 9 7 13
3 2
5 8
6 9
7 4
1 10

result:

ok Accepted with 4+9 operations,sum of size(s)=7+13

Test #8:

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

input:

1
1401446296
100 100 10000 10000
5
4125806477 4125806476
1224445301 1224445291
1474144594 1474144597
2898586557 2898586536
879608888 879608877
3110900945 3110900930
2490037068 2490037051
422424582 422424570
1017432306 1017432295

output:

Succeeded
4 9 12 11
10 7
5 3
9 8
4 2
1 6

result:

ok Accepted with 4+9 operations,sum of size(s)=12+11

Test #9:

score: 3
Accepted
time: 1ms
memory: 5420kb

input:

1
1756894897
100 100 10000 10000
5
2081532117 2081532115
4275738287 4275738273
632146529 632146534
2424607270 2424607263
2157363450 2157363443
2463928559 2463928550
3381117807 3381117785
4186361975 4186361960
3382018566 3382018532

output:

Succeeded
3 9 6 6
9 7
5 8
6 10
2 3
1 4

result:

ok Accepted with 3+9 operations,sum of size(s)=6+6

Test #10:

score: 3
Accepted
time: 1ms
memory: 5204kb

input:

1
1465320926
100 100 10000 10000
5
2695813796 2695813789
3049323317 3049323309
231883125 231883119
3073242409 3073242392
1388430756 1388430755
183732731 183732729
1423324287 1423324267
3470698806 3470698795
354321542 354321525

output:

Succeeded
4 9 6 9
2 6
3 9
10 7
8 4
1 5

result:

ok Accepted with 4+9 operations,sum of size(s)=6+9

Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

2
755640766
20000 10000 200000 200000
100
4287951944 4287951892
218593589 218593610
2907028702 2907028595
100123056 100122959
3149201405 3149201229
3454414687 3454414608
1901257489 1901257490
1532337798 1532337686
836222214 836222227
187381584 187381446
1847826999 1847827071
2868544732 2868544653
41...

output:

Unauthorized output

result:


Subtask #3:

score: 8
Accepted

Test #19:

score: 8
Accepted
time: 15ms
memory: 5832kb

input:

3
397960972
100000 4000 200000 200000
1000
3136131587 3136131078
3887641427 3887642253
280951546 280951198
124187343 124186744
3948118891 3948118785
2174920490 2174920140
3041102338 3041103477
489656932 489656480
3093689453 3093690199
3027233105 3027233261
967551350 967551424
215138938 215138436
251...

output:

Succeeded
544 1999 1087 1088
1366 1855
1773 1563
1969 1275
1368 1313
1107 1409
1643 1727
1134 1837
1844 1600
1677 1114
1610 1937
1122 1588
1630 1298
1829 1755
1561 1178
1852 1357
1347 1394
1751 1054
1806 1887
1164 1266
1868 1579
1824 1609
1613 1276
1697 1078
1272 1866
1009 1554
1477 1223
1462 1214
1...

result:

ok Accepted with 544+1999 operations,sum of size(s)=1087+1088

Test #20:

score: 8
Accepted
time: 16ms
memory: 5932kb

input:

3
755523510
100000 4000 200000 200000
999
837610461 837610217
209552123 209552158
2202987134 2202987346
3933843218 3933843131
2783546817 2783547323
415275024 415276142
13876082 13876176
448702939 448703028
1294393612 1294394136
3910397405 3910397094
3416630484 3416630700
3215888394 3215888948
124509...

output:

Succeeded
56 1997 111 112
346 728
1690 13
468 49
745 103
897 485
86 149
82 913
735 826
408 750
83 41
202 365
124 414
301 1200
283 843
694 77
156 266
789 840
767 1764
878 938
959 618
90 1564
249 20
275 51
396 994
585 1144
732 429
692 85
234 665
739 380
1630 969
449 626
884 132
558 583
1634 660
344 50...

result:

ok Accepted with 56+1997 operations,sum of size(s)=111+112

Test #21:

score: 8
Accepted
time: 13ms
memory: 5764kb

input:

3
2042812129
100000 4000 200000 200000
998
3075748308 3075748844
1569673104 1569672823
3968525693 3968524672
2108387096 2108386924
3356390455 3356391094
3372812724 3372813320
3904961007 3904958854
4029621824 4029621345
4114486509 4114486281
1387138301 1387138067
124292409 124292880
3935517019 393551...

output:

Succeeded
704 1995 1407 1408
1749 1325
1332 1702
1225 1114
1397 1984
1307 1723
1658 1737
1813 1495
1838 1051
1067 1316
1696 1922
1946 1402
1363 1355
1208 1886
1539 1247
1505 1072
1624 1700
1436 1499
1268 1498
1326 1759
1857 1659
1920 1293
1242 1651
1311 1523
1687 1751
1347 1336
1021 1810
1147 1366
1...

result:

ok Accepted with 704+1995 operations,sum of size(s)=1407+1408

Test #22:

score: 8
Accepted
time: 16ms
memory: 5940kb

input:

3
1597029305
100000 4000 200000 200000
998
2980500284 2980500361
2247716226 2247714887
988714926 988714253
1734063960 1734064121
2359409219 2359409008
411968449 411968499
155449826 155451318
555582797 555582911
45071917 45071590
1460631113 1460629818
3059213925 3059213709
2094519932 2094519250
38721...

output:

Succeeded
220 1995 439 440
345 1767
528 262
38 580
910 1719
226 1612
1016 1391
719 1557
130 431
941 1537
322 1894
1024 1572
1082 1713
697 1539
1712 846
1898 1100
1595 293
1512 1970
685 119
1521 748
245 282
419 551
1688 1301
774 857
1177 488
1558 1854
1579 1950
576 1136
219 1600
1643 760
887 167
1762...

result:

ok Accepted with 220+1995 operations,sum of size(s)=439+440

Test #23:

score: 8
Accepted
time: 12ms
memory: 5844kb

input:

3
1564467111
100000 4000 200000 200000
1000
1236547222 1236547523
2135786902 2135787064
2523622442 2523622714
1532839693 1532838477
818219113 818220033
676117995 676118414
570037547 570036834
514220702 514220842
3399494183 3399495268
2654728241 2654729498
1495037081 1495037412
2062047312 2062048382
...

output:

Succeeded
281 1999 561 562
1276 1367
489 340
602 1496
21 783
1715 1597
1344 994
11 298
1003 1693
643 1737
268 709
237 552
1391 1974
878 1055
796 852
371 1345
1289 209
164 813
1499 1840
1936 1960
1188 357
1491 137
873 1488
537 279
151 724
696 1950
521 291
1920 424
260 1798
711 1166
1638 1429
280 53
1...

result:

ok Accepted with 281+1999 operations,sum of size(s)=561+562

Test #24:

score: 8
Accepted
time: 15ms
memory: 5876kb

input:

3
213138336
100000 4000 200000 200000
999
1130123143 1130122958
687694550 687694095
929485247 929484829
3680984473 3680983776
3074105335 3074104892
1342732123 1342731927
1364720805 1364720672
2077428724 2077428538
28510235 28511166
937776441 937776505
3414480885 3414480666
3148182306 3148181509
3485...

output:

Succeeded
420 1997 839 840
581 837
276 427
423 84
646 90
760 277
28 687
444 530
895 5
141 21
458 497
381 564
27 237
465 271
231 293
524 808
104 79
755 301
482 596
998 390
498 147
951 351
580 283
246 754
884 60
412 647
398 402
1356 817
1915 258
645 363
662 138
953 967
324 379
567 543
494 492
556 961
...

result:

ok Accepted with 420+1997 operations,sum of size(s)=839+840

Test #25:

score: 8
Accepted
time: 15ms
memory: 6140kb

input:

3
924980045
100000 4000 200000 200000
998
1666991999 1666991279
148686690 148685590
324531768 324531788
2043725358 2043725640
1133184972 1133184631
853139746 853139683
1770837584 1770837761
1481554510 1481554714
1372084869 1372084950
1756084441 1756085236
2107756067 2107756010
3377586774 3377586312
...

output:

Succeeded
22 1995 43 44
874 702
412 78
608 551
662 661
473 1099
406 745
447 1850
481 28
714 746
511 411
317 738
582 949
1464 825
664 890
407 670
674 358
423 445
808 534
1963 327
360 549
219 878
860 851
665 623
533 419
141 1161
59 356
575 244
232 986
384 726
1373 127
364 915
353 806
463 654
333 785
1...

result:

ok Accepted with 22+1995 operations,sum of size(s)=43+44

Test #26:

score: 8
Accepted
time: 13ms
memory: 5824kb

input:

3
774146483
100000 4000 200000 200000
999
3478842381 3478843345
606332045 606332562
2701123033 2701123563
3216754910 3216755036
1217043418 1217043429
1501603802 1501603474
1778234551 1778234769
1444790432 1444791022
2502984240 2502984288
856947428 856947122
1363006586 1363006323
1995567044 199556642...

output:

Succeeded
741 1997 1481 1482
436 233
112 55
125 711
394 874
462 419
1792 171
552 184
927 271
160 608
764 470
611 397
705 165
172 819
174 978
633 153
57 937
482 128
508 971
894 940
34 1740
314 835
261 720
801 868
751 322
628 816
717 1659
961 325
51 590
760 203
339 623
9 1905
447 120
375 181
575 880
2...

result:

ok Accepted with 741+1997 operations,sum of size(s)=1481+1482

Test #27:

score: 8
Accepted
time: 16ms
memory: 5860kb

input:

3
82266506
100000 4000 200000 200000
999
3056998601 3056998876
1887811910 1887812134
1616045105 1616045172
1784967209 1784967615
650919784 650918837
4290024152 4290024396
154133667 154133653
754913686 754913998
3014551042 3014550770
3332698384 3332698431
304657473 304657856
1466514044 1466515029
313...

output:

Succeeded
180 1997 359 360
426 569
954 125
1700 850
692 743
417 195
1125 668
971 962
270 563
421 865
285 655
989 772
467 525
348 317
122 412
59 1665
633 73
62 527
671 709
558 157
156 402
918 910
886 707
799 225
613 410
738 737
115 472
795 321
159 777
263 134
362 963
388 1175
166 985
301 409
193 407
...

result:

ok Accepted with 180+1997 operations,sum of size(s)=359+360

Test #28:

score: 8
Accepted
time: 16ms
memory: 5836kb

input:

3
1746021239
100000 4000 200000 200000
1000
3649747382 3649747015
3895797253 3895797184
4001365723 4001365122
564220364 564220085
362710516 362710456
2800243662 2800243024
2073687310 2073687797
145701776 145700951
492159209 492159366
3076148714 3076148148
1548738755 1548739322
3580263095 3580262700
...

output:

Succeeded
349 1999 697 698
272 707
532 433
503 900
769 486
508 264
1196 252
696 108
874 656
755 924
878 1299
439 307
17 717
89 531
247 392
987 233
719 314
47 79
660 217
151 784
669 713
615 187
73 783
633 941
908 356
789 880
378 722
26 971
241 326
69 352
683 584
1202 330
708 1729
139 447
435 760
538 ...

result:

ok Accepted with 349+1999 operations,sum of size(s)=697+698

Subtask #4:

score: 0
Time Limit Exceeded

Test #29:

score: 0
Time Limit Exceeded

input:

4
1084797752
100000 4000 200000 200000
1000
3456536122 3456534568
249115651 249115791
3576312078 3576312237
1880897416 1880895547
1944688480 1944688327
248846397 248847256
3567405828 3567405196
1084965392 1084965206
1435956247 1435955729
3887033767 3887032464
307260230 307260472
1476733874 147673312...

output:

Unauthorized output

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #39:

score: 0
Time Limit Exceeded

input:

5
1720909858
50000 4000 200000 100000
998
195378529 195378218
2138942224 2138942028
2421726252 2421725316
2614111628 2614111784
3778296551 3778295886
3346314089 3346313971
701234060 701233448
279201944 279202119
69826850 69826766
2173156660 2173157126
2982274003 2982273048
2306106121 2306107345
2808...

output:

Unauthorized output

result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #50:

score: 0
Time Limit Exceeded

input:

6
889180297
25000 4000 200000 100000
998
3680334935 3680334330
2957217208 2957215867
3096097757 3096097331
2843029536 2843030717
2270437916 2270437982
1841161075 1841160444
3671823118 3671823208
2166904224 2166903071
2760262295 2760263328
880472976 880472564
3147819342 3147820514
3366602035 33666019...

output:

Unauthorized output

result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #59:

score: 0
Time Limit Exceeded

input:

7
1561772597
25000 4000 200000 100000
1000
834919143 834919090
162625904 162627303
1067517190 1067517712
3410644901 3410644677
2728503196 2728502622
4133685425 4133685598
976760503 976760426
2101358026 2101358499
3583017242 3583017016
1743218912 1743220527
2609984627 2609985177
3915259025 3915259188...

output:

Unauthorized output

result:


Subtask #8:

score: 0
Time Limit Exceeded

Test #70:

score: 0
Time Limit Exceeded

input:

8
1311447458
50000 100000 500000 200000
4999
173190562 173182163
1078196947 1078197142
1215565665 1215571165
1186082670 1186081354
2422459084 2422459806
2626070241 2626074599
207492448 207494582
2266700305 2266695214
1679673055 1679672568
3879988278 3879982030
254940475 254941572
3919251618 39192495...

output:

Unauthorized output

result:


Subtask #9:

score: 0
Time Limit Exceeded

Test #81:

score: 0
Time Limit Exceeded

input:

9
574951428
15000 10000 200000 50000
5000
1781472251 1781466624
803445324 803444785
3544280892 3544283003
3151400420 3151403948
3250864128 3250871501
4189507543 4189510374
3483519516 3483520446
1003612935 1003617460
1101934749 1101931586
1948046579 1948042301
4151407804 4151401951
424123439 42412196...

output:

Unauthorized output

result: