QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515017#2269. To be Connected, or not to be, that is the QuestionLavender_Field#WA 34ms11452kbC++201.8kb2024-08-11 14:30:362024-08-11 14:30:36

Judging History

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

  • [2024-08-11 14:30:36]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:11452kb
  • [2024-08-11 14:30:36]
  • 提交

answer

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
using namespace std;
inline int rd() {
	int r = 0; bool w = false; char ch = getchar();
	while( ch < '0' || ch > '9' ) w = !(ch^45), ch = getchar();
	while( ch >= '0' && ch <='9' ) r = (r<<1) + (r<<3) + (ch^48), ch = getchar();
	return w ? -r : r;
}

#define MAXN 100000
int n, m;
vector<int> to[MAXN+5];
int val[MAXN+5], dot[MAXN+5], lnum[MAXN+5], rnum[MAXN+5];
bool cmp_dot( int a , int b ) {
	return val[a] < val[b];
}
int a[MAXN+5];
int fa[MAXN+5], cnt, mincnt;
int find( int x ) {
	if( fa[x] == x ) return x;
	return fa[x] = find(fa[x]);
}
int main() {
	n = rd(), m = rd();
	FOR(i,1,n) val[i] = rd(), dot[i] = i;
	sort(dot+1, dot+1+n, cmp_dot);
	if( val[dot[1]] == val[dot[n]] ) {
		puts("-1");
		return 0;
	}
	FOR(i,1,m) {
		int u = rd(), v = rd();
		to[u].pb(v), to[v].pb(u);
	}
	FOR(i,1,n) fa[i] = i; cnt = 0, mincnt = 0;
	FOR(i,1,n) {
		while( val[cnt+1] == val[i] && cnt < n ) ++cnt;
		int u = dot[i];
		for(auto v: to[u]) if( val[v] <= val[u] ) {
			if( find(v) != find(u) ) {
				++mincnt;
				fa[find(v)] = find(u);
			}
		}
		lnum[i] = cnt - mincnt;
	}
	FOR(i,1,n) fa[i] = i; cnt = 0, mincnt = 0;
	ROF(i,n,1) {
		while( val[n-cnt] == val[i] && cnt < n ) ++cnt;
		int u = dot[i];
		for(auto v: to[u]) if( val[v] >= val[u] ) {
			if( find(v) != find(u) ) {
				++mincnt;
				fa[find(v)] = find(u);
			}
		}
		rnum[i] = cnt - mincnt;
	}
//	FOR(i,1,n) printf("%d ", lnum[i]); putchar('\n');
//	FOR(i,1,n) printf("%d ", rnum[i]); putchar('\n');
	int ans = -1;
	FOR(i,1,n-1) if( val[dot[i]] != val[dot[i-1]] ) {
		if( i - lnum[i] + 1 >= rnum[i+1] && (n-i) - rnum[i+1] + 1 >= lnum[i] ) {
			ans = val[dot[i]];
			break;
		}
	}
	printf("%d", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 0
861866350 106689920

output:

106689920

result:

ok single line: '106689920'

Test #2:

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

input:

3 0
582295931 120217528 845887275

output:

-1

result:

ok single line: '-1'

Test #3:

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

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: 10ms
memory: 6400kb

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: 34ms
memory: 11452kb

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: 25ms
memory: 10016kb

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: 29ms
memory: 11176kb

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: 24ms
memory: 9772kb

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: 3ms
memory: 6536kb

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: 2ms
memory: 6092kb

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: 25ms
memory: 8852kb

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: 9ms
memory: 6648kb

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: 2ms
memory: 5984kb

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: -100
Wrong Answer
time: 27ms
memory: 8588kb

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:

129572147

result:

wrong answer 1st lines differ - expected: '121013858', found: '129572147'