QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#94528#2269. To be Connected, or not to be, that is the Questionwhatever#AC ✓68ms11916kbC++231.3kb2023-04-06 16:00:232023-04-06 16:00:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-06 16:00:24]
  • 评测
  • 测评结果:AC
  • 用时:68ms
  • 内存:11916kb
  • [2023-04-06 16:00:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m; cin >> n >> m;
	vector<int> a(n);
	for(int &x : a) cin >> x;
	vector<vector<int>> G(n);
	for(int i = 0; i < m; i ++) {
		int u, v; cin >> u >> v;
		G[-- u].emplace_back(-- v);
		G[v].emplace_back(u);
	}
	vector<int> id(n);
	iota(id.begin(), id.end(), 0);
	sort(id.begin(), id.end(), [&] (int x, int y) {return a[x] < a[y];});
	struct dsu_t {
		vector<int> fa;
		dsu_t(int n) : fa(n) {iota(fa.begin(), fa.end(), 0);}
		int find(int x) {return fa[x] == x ? x : fa[x] = find(fa[x]);}
		bool merge(int u, int v) {
			u = find(u), v = find(v);
			return u != v ? fa[u] = v, 1 : 0;
		}
	};
	
	auto solve = [&] {
		dsu_t dsu(n);
		vector<int> ans(n), vis(n);
		int cnt = 0;
		for(int i = 0; i < n; i ++) {
			int u = id[i];
			vis[u] = 1;
			for(auto v : G[u]) if(vis[v]) {
				cnt += dsu.merge(u, v);
			}
			ans[i] = cnt;
		}
		return ans;
	};
	auto x = solve();
	reverse(id.begin(), id.end());
	auto y = solve();
	reverse(y.begin(), y.end());
	reverse(id.begin(), id.end());
	for(int i = 0; i < n - 1; i ++) if(a[id[i]] != a[id[i + 1]]) {
		if(n - 1 - x[i] - y[i + 1] <= min(i + 1, n - i - 1)) {
			cout << a[id[i]] << '\n';
			exit(0);
		}
	}
	cout << -1 << '\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3412kb

input:

2 0
861866350 106689920

output:

106689920

result:

ok single line: '106689920'

Test #2:

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

input:

3 0
582295931 120217528 845887275

output:

-1

result:

ok single line: '-1'

Test #3:

score: 0
Accepted
time: 11ms
memory: 5468kb

input:

52033 0
432755200 936478974 298744051 31368207 847742874 81290408 425992405 651328821 903238557 526933479 356290128 722885083 779029575 480262946 443316470 542413465 170562283 440427743 438763956 784112617 255213130 899556824 323259505 857165776 533714690 565510843 859610987 686006833 211894364 9600...

output:

-1

result:

ok single line: '-1'

Test #4:

score: 0
Accepted
time: 29ms
memory: 7652kb

input:

100000 0
514837648 759500586 899265033 24085608 545610751 221779667 568755229 169602804 284396186 169538713 571993850 645890208 375601406 769765103 805781464 228017324 648075651 874669052 771742115 269678248 190757592 220852391 275602630 816966668 111244645 208546040 715493307 277760893 770626133 25...

output:

-1

result:

ok single line: '-1'

Test #5:

score: 0
Accepted
time: 50ms
memory: 11208kb

input:

100000 99999
299608910 294889223 380597480 583050141 733930013 271705935 623956575 293208851 168678637 517320846 970153874 376864085 620559158 384944405 959726556 311522848 233740144 852169507 874336822 670072232 182817184 163689537 962302870 278762094 916902553 742474244 377317908 941252256 1153825...

output:

500886962

result:

ok single line: '500886962'

Test #6:

score: 0
Accepted
time: 38ms
memory: 8876kb

input:

74426 74425
502580802 844381862 660278137 133338847 482745545 247460402 538172402 808255530 40356010 108510584 849411507 316373292 792804254 963129923 254086752 499276056 480699103 83684034 315438237 930422686 782095189 819730693 122590837 465841667 953771312 705072601 968407044 458518835 349083576 ...

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 53ms
memory: 10792kb

input:

100000 99999
133839735 839421523 924352573 520827568 797215018 605505884 915386299 722513810 563857619 374933496 671611549 755041992 574094436 811166689 71846864 318787217 600593733 432248687 427265817 124707250 949283604 266862856 403000555 154170331 108034441 805939165 428287602 320849230 17215718...

output:

-1

result:

ok single line: '-1'

Test #8:

score: 0
Accepted
time: 46ms
memory: 9228kb

input:

79196 79195
27470775 804067741 528420908 540966883 169917452 913909399 888701203 243851365 916310118 431848112 73723370 255797403 107510224 27470775 530696085 34479706 5055932 828895468 640285511 109742378 638349414 525486336 642444296 73723370 130703807 721930556 370096035 83165372 169917452 598598...

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 10ms
memory: 4220kb

input:

316 49770
402309991 388232745 117230681 667364510 609127965 719159826 46096555 263572336 872818339 743676811 930143789 620358596 734088816 269266232 367069875 806292502 103977149 197983827 999190721 514994027 316161699 30791878 20017163 407458420 165022887 41938828 431324792 12859815 590746093 42978...

output:

6040560

result:

ok single line: '6040560'

Test #10:

score: 0
Accepted
time: 6ms
memory: 3636kb

input:

226 25425
918052497 947313394 787933966 711247447 776043131 194858630 665217850 628747789 257073683 537341760 94655430 493762787 944038901 408821094 93806710 298190132 26738949 904560347 310515734 76433554 369449419 72302169 244532795 512646058 565125853 370721601 890126984 55784423 873331667 387197...

output:

2061226

result:

ok single line: '2061226'

Test #11:

score: 0
Accepted
time: 41ms
memory: 7804kb

input:

50000 99995
361130420 217854966 892557428 211066048 61878746 1712505 734659286 672475419 253910757 211846066 957016890 403739705 883039467 914321733 906904982 164015952 347109090 747151597 259133771 401129332 732618453 559653504 310468488 783148465 654522500 381526230 447488941 937320105 500322448 9...

output:

119201812

result:

ok single line: '119201812'

Test #12:

score: 0
Accepted
time: 17ms
memory: 4964kb

input:

15493 40061
917454961 835297134 39389776 98116751 41620521 230332188 333065827 156213436 402763834 175546650 812958918 121348056 457276166 871161640 691830399 574512208 466230206 778645912 606018943 202810608 369213038 663337965 642497305 614377372 115949322 692501727 785446317 395114438 949967622 8...

output:

54626072

result:

ok single line: '54626072'

Test #13:

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

input:

2606 7024
459423570 776425997 575613451 911877779 762277599 374745627 466815572 265268799 122117935 527122748 662100991 898653501 471862707 558657540 366776135 57656030 742070198 838282223 219902759 809818832 212116475 300321794 389315650 936814763 416714101 317977253 201364516 223505269 172096239 5...

output:

62776648

result:

ok single line: '62776648'

Test #14:

score: 0
Accepted
time: 43ms
memory: 7908kb

input:

50000 99993
292406122 762464474 829092468 761425338 676392968 586364101 834509930 565758784 434170174 679548067 565758784 387724742 180123438 312642030 548503509 321359647 762909119 175464172 715371696 548503509 6371186 355614955 906779941 69505221 321714458 544986516 628819800 683653451 904221779 6...

output:

121013858

result:

ok single line: '121013858'

Test #15:

score: 0
Accepted
time: 33ms
memory: 7320kb

input:

41555 96239
698588585 926607576 135038594 957507167 920794080 730922079 332303247 900863327 30874346 695378271 513906191 695378271 296757700 346315223 414209455 895409108 942463533 292481795 280646081 871057727 828299057 515991015 42550782 129060740 882182241 59337692 154597021 59337692 619458793 94...

output:

78812934

result:

ok single line: '78812934'

Test #16:

score: 0
Accepted
time: 22ms
memory: 6884kb

input:

35732 88032
704858581 828296440 203627790 129059533 150974966 295186326 476525822 394597865 543719838 975310062 879833794 100922193 836658557 157302116 965197316 975310062 234696045 291385855 364497765 394646434 383310895 177930686 966249122 934573640 152014453 295186326 812734169 640089788 86080189...

output:

65052170

result:

ok single line: '65052170'

Test #17:

score: 0
Accepted
time: 27ms
memory: 7256kb

input:

50000 53682
410008651 925287 108579857 334514860 792957074 127486816 395164611 441595237 306463435 896114295 278493177 442931777 83041154 576656851 475469819 623531118 656689200 509690363 403151953 849285567 918722509 812523361 209027615 121849577 196513013 505117576 256018556 269528866 831763709 29...

output:

456936470

result:

ok single line: '456936470'

Test #18:

score: 0
Accepted
time: 13ms
memory: 5428kb

input:

26650 30742
320225979 58794409 357435670 234505494 700978137 672144298 603172939 907372118 785962315 420738019 383854992 982547445 316380201 79988815 866151559 338047878 677955260 89530505 294826721 261653255 250208634 241059461 867054277 617710251 593974613 887322441 144164291 29201511 307987076 46...

output:

407034704

result:

ok single line: '407034704'

Test #19:

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

input:

6152 3255
549559611 596493423 467704125 21443984 37871125 60356531 885554306 552778463 123668303 145122095 546641654 134322045 31590421 263682462 650648019 317302186 754943307 584920440 240733435 699986928 864627382 562865084 316282521 507317110 383996211 78956278 186082865 519069374 853865366 51325...

output:

-1

result:

ok single line: '-1'

Test #20:

score: 0
Accepted
time: 30ms
memory: 7408kb

input:

50000 66786
119725578 448672907 997515629 721305800 997515629 341390341 905164068 984823815 392784340 229608418 475510517 206823170 505734092 712142560 648487013 717889117 176308491 421774239 565404737 941593132 505734092 483146698 493222979 199504725 85108656 99373100 775437838 249817824 876292645 ...

output:

303667283

result:

ok single line: '303667283'

Test #21:

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

input:

22334 23860
210824725 847962002 518696527 946482682 898345304 568587454 13925707 82516170 215439290 349872680 719233614 747317731 518931296 883189332 561930383 629712849 319807884 287640444 959105461 255559282 860544345 345455486 948460477 472929513 11197783 554718385 518931296 121634241 210824725 5...

output:

358934724

result:

ok single line: '358934724'

Test #22:

score: 0
Accepted
time: 13ms
memory: 5372kb

input:

21856 41879
995306375 696239211 384931037 60410065 684522781 617704450 138940210 866013659 340059979 866464838 660382391 787296991 96505764 684522781 470938389 223586930 745854861 768552642 866464838 661444883 993236101 39437911 403820799 114582837 375796220 697294981 881841523 845425991 906328357 6...

output:

134872096

result:

ok single line: '134872096'

Test #23:

score: 0
Accepted
time: 68ms
memory: 10500kb

input:

100000 98533
606853112 207922160 251675256 593659123 365920991 805056194 743364293 445814678 715689206 683430715 208713960 720825823 823806187 853696621 597225033 158808071 265642204 820489761 977781710 687046674 188257835 484685402 508558441 32188059 793184239 573234032 832775276 571872655 93660470...

output:

-1

result:

ok single line: '-1'

Test #24:

score: 0
Accepted
time: 27ms
memory: 6800kb

input:

58772 26160
515131722 836852682 906786515 167922934 182718283 898463434 797363005 392348030 807493502 323600533 780658907 398883337 431197239 676169141 611167447 332608761 456331503 220585287 978407256 465988104 875576111 580876765 601166145 51740373 687083869 122807734 117194418 961233584 285782631...

output:

-1

result:

ok single line: '-1'

Test #25:

score: 0
Accepted
time: 46ms
memory: 10280kb

input:

100000 79065
262856520 427969193 952691384 825631001 916540400 391674700 229441971 874502687 202788180 656429302 868728232 292564029 798299078 33788876 569997268 132921891 211011321 205464104 391674700 340895668 749991906 552489522 272998686 521814040 444700633 149623099 272998686 404810085 34297018...

output:

-1

result:

ok single line: '-1'

Test #26:

score: 0
Accepted
time: 26ms
memory: 6792kb

input:

42025 64496
482832518 280479279 472670579 370565943 557960268 799235986 85330897 354828847 279780859 723408404 717266183 373074917 955837529 487416606 556627743 976087737 20795143 883558438 915905931 761201892 462628511 507005077 65522791 261045717 542393361 680150564 682112946 542393361 376662822 6...

output:

266759861

result:

ok single line: '266759861'

Test #27:

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

input:

95 2224
564969098 696909824 734817353 268315413 411213837 283344521 554671583 380848576 636753610 538311235 732448130 315024225 706544563 842604615 350783810 608967363 37169079 509087774 921792073 646925650 967264133 331423246 520329466 376562399 78268344 10366615 964145829 420898987 39271359 505854...

output:

10366615

result:

ok single line: '10366615'

Test #28:

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

input:

9 19
468248487 136653540 135751620 710851377 311362055 568841431 289816398 294980900 319463953
2 5
1 8
1 9
8 9
6 7
4 7
5 8
4 8
6 9
6 8
5 7
3 4
1 2
5 9
2 9
3 5
4 9
5 6
2 6

output:

135751620

result:

ok single line: '135751620'

Test #29:

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

input:

63 668
545325993 619054703 273034607 638323709 133379523 499275122 397006928 630440449 663938190 910058259 171305422 988553440 196956243 85132658 590683049 30418538 600655624 371582125 90508169 926714703 775019702 216300533 901648037 565623513 140242948 294717026 654665882 260942140 543272562 859205...

output:

30418538

result:

ok single line: '30418538'

Test #30:

score: 0
Accepted
time: 1ms
memory: 3464kb

input:

78 1120
493248300 880875558 734672747 396525309 493248300 791667830 791667830 396525309 420039534 734672747 880875558 566486903 880875558 396525309 396525309 566486903 612623225 566486903 420039534 880875558 493248300 396525309 118014707 566486903 118014707 396525309 118014707 791667830 396525309 49...

output:

118014707

result:

ok single line: '118014707'

Test #31:

score: 0
Accepted
time: 1ms
memory: 3344kb

input:

19 41
44536643 422558410 235982024 780061372 273500748 189706732 44536643 44536643 44536643 404862896 847636519 273500748 422558410 847636519 847636519 273500748 404862896 780061372 235982024
11 18
10 18
3 18
13 16
4 6
12 13
11 15
9 12
1 10
8 12
4 19
14 17
1 2
3 17
2 13
7 18
13 18
10 19
11 19
14 18
...

output:

44536643

result:

ok single line: '44536643'

Test #32:

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

input:

92 2053
6392386 171063743 6392386 171063743 314834805 171063743 63067838 532112244 171063743 314834805 314834805 426642326 426642326 532112244 532112244 484363014 753378988 640982224 753378988 42767876 314834805 171063743 426642326 42767876 6392386 314834805 484363014 640982224 314834805 484363014 1...

output:

6392386

result:

ok single line: '6392386'

Test #33:

score: 0
Accepted
time: 35ms
memory: 9496kb

input:

100000 41108
930294654 362926060 476714091 399334824 225239068 50455291 116423421 524102760 592470757 528650092 679071551 175985612 177393137 429999963 819959853 503196044 248164307 502990935 398183316 133735827 574165428 344271704 132840660 476630972 840939383 193220181 65341344 763050057 67884162 ...

output:

-1

result:

ok single line: '-1'

Test #34:

score: 0
Accepted
time: 18ms
memory: 5604kb

input:

41504 18418
388401161 200257360 161820801 299041224 420375537 914795792 590232045 602603385 154764219 102948033 680617548 169680142 982927963 159716804 899623476 437881083 458333260 374134978 210309891 150478861 687134304 173117859 685672842 924416909 673739677 171032628 164376848 984287105 92233806...

output:

-1

result:

ok single line: '-1'

Test #35:

score: 0
Accepted
time: 30ms
memory: 9632kb

input:

100000 43709
668816556 239154673 899187374 141083479 922627757 448458571 530573872 172267817 621525202 324418014 761900898 885106683 481894626 410594651 949262733 804607549 213228288 287571227 523793597 476841934 490919161 887877147 516918896 637179655 922627757 342870591 987254521 143863995 7795804...

output:

-1

result:

ok single line: '-1'

Test #36:

score: 0
Accepted
time: 22ms
memory: 6864kb

input:

63219 19427
924860519 324078726 279488 494884243 566245405 980798202 374276718 566245405 288273323 452929346 810239823 882667508 445469351 335804449 493795723 911892807 133320777 600003872 892363502 832517863 143799345 75180516 132375658 765273885 955400666 124217214 829613099 61287005 972364279 492...

output:

-1

result:

ok single line: '-1'

Test #37:

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

input:

2 0
568670903 568670903

output:

-1

result:

ok single line: '-1'

Test #38:

score: 0
Accepted
time: 18ms
memory: 7668kb

input:

100000 0
779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 779177767 7...

output:

-1

result:

ok single line: '-1'

Test #39:

score: 0
Accepted
time: 41ms
memory: 10936kb

input:

100000 99999
573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 573845956 5738459...

output:

-1

result:

ok single line: '-1'

Test #40:

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

input:

316 49770
540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 540491988 ...

output:

-1

result:

ok single line: '-1'

Test #41:

score: 0
Accepted
time: 36ms
memory: 11916kb

input:

100000 99999
520200076 616920339 934592715 967927395 202060848 469958095 710523656 855011034 893733263 740246862 411996592 894642013 252479290 901724031 744669082 649828038 701143904 946218376 136977917 202653642 468643941 626904632 287272256 409166673 747544541 936630941 877621668 513171931 6804990...

output:

999972791

result:

ok single line: '999972791'

Test #42:

score: 0
Accepted
time: 36ms
memory: 10536kb

input:

86259 86258
433468967 549889539 637482972 461074190 233229892 42008759 786605496 528836302 925458060 9958308 411940065 186327834 482864350 617133374 217531395 594970136 24017588 269236208 941588618 273792400 857338238 46606511 120710683 795395104 970540235 24482817 894257182 580527083 445847949 5607...

output:

496654351

result:

ok single line: '496654351'

Test #43:

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

input:

6696 6695
551140495 49882589 328525759 23533356 918200518 821170039 74534080 597868598 204097988 746170210 163262186 755133108 667314859 364899340 23533356 184377979 632639270 458061016 159240200 856740438 983981333 45275663 204097988 141446211 983981333 382505612 938729875 669394586 234773101 59786...

output:

429782085

result:

ok single line: '429782085'