QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#515035 | #2269. To be Connected, or not to be, that is the Question | Lavender_Field# | WA | 37ms | 11436kb | C++20 | 2.2kb | 2024-08-11 14:42:00 | 2024-08-11 14:42:00 |
Judging History
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, p;
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, p = 0;
FOR(i,1,n) {
while( val[dot[cnt+1]] == val[dot[i]] && cnt < n ) ++cnt;
while( val[dot[p+1]] == val[dot[i]] && p < n ) {
++p;
int u = dot[p];
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, p = n+1;
ROF(i,n,1) {
while( val[dot[n-cnt]] == val[dot[i]] && cnt < n ) ++cnt;
while( val[dot[p-1]] == val[dot[i]] && p > 1 ) {
--p;
int u = dot[p];
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(int i=1;i<n;++i) {
while( val[dot[i+1]] == val[dot[i]] && i < n ) ++i;
if( i - lnum[i] + 1 >= rnum[i+1] && (n-i) - rnum[i+1] + 1 >= lnum[i] ) {
ans = val[dot[i]];
break;
}
}
// FOR(i,1,n-1) if( val[dot[i]] != val[dot[i-1]] ) {
// printf("%d\n", i);
// 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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5904kb
input:
2 0 861866350 106689920
output:
106689920
result:
ok single line: '106689920'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6004kb
input:
3 0 582295931 120217528 845887275
output:
-1
result:
ok single line: '-1'
Test #3:
score: 0
Accepted
time: 9ms
memory: 6064kb
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: 11ms
memory: 6244kb
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: 37ms
memory: 11304kb
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: 27ms
memory: 9668kb
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: -100
Wrong Answer
time: 36ms
memory: 11436kb
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:
999699794
result:
wrong answer 1st lines differ - expected: '-1', found: '999699794'