QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739737#2269. To be Connected, or not to be, that is the Questionk1nsomWA 51ms28972kbC++142.5kb2024-11-12 22:54:502024-11-12 22:54:55

Judging History

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

  • [2024-11-12 22:54:55]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:28972kb
  • [2024-11-12 22:54:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ednl '\n'
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, m, tot, a[N], b[N], pre[N], suf[N], f[N], p[N], s[N];
vector<int> e[N], tr[N];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i], b[++tot] = a[i], f[i] = i;
    sort(b + 1, b + 1 + tot);
    tot = unique(b + 1, b + 1 + tot) - b - 1;
    for (int i = 1; i <= n; i++)
        a[i] = lower_bound(b + 1, b + 1 + tot, a[i]) - b, tr[a[i]].push_back(i);
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        pre[min(a[u], a[v])]++;
        suf[max(a[u], a[v])]++;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for (int i = tot; i >= 1; i--)
        pre[i] += pre[i + 1];
    for (int i = 1; i <= tot; i++)
        suf[i] += suf[i - 1];
    // for (int i = 1; i <= tot; i++)
    //     cout << pre[i] << ' ';
    // cout << endl;
    int cnt = 0, js = 0;
    for (int i = 1; i <= tot; i++)
    {
        for (auto u : tr[i])
        {
            ++cnt;
            for (auto to : e[u])
                if (a[to] <= a[u])
                {
                    int x = find(u), y = find(to);
                    if (x != y)
                    {
                        f[x] = y;
                        cnt--;
                    }
                }
        }
        p[i] = cnt;
    }
    for (int i = 1; i <= n; i++)
        f[i] = i;
    cnt = 0;
    for (int i = tot; i >= 1; i--)
    {
        for (auto u : tr[i])
        {
            ++cnt;
            for (auto to : e[u])
                if (a[to] >= a[u])
                {
                    int x = find(u), y = find(to);
                    if (x != y)
                    {
                        f[x] = y;
                        cnt--;
                    }
                }
        }
        s[i] = cnt;
    }
    cnt = 0, js = 0;
    for (int i = 1; i <= tot; i++)
    {
        for (auto u : tr[i])
            js++;
        // cout << js << ' ' << p[i] << ' ' << s[i] << ' ' << pre[i + 1] << endl;
        if (js && n - js && p[i] - 1 <= pre[i + 1] && s[i + 1] - 1 <= suf[i])
        {
            cout << b[i] << endl;
            return;
        }
    }
    cout << -1 << endl;
}
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 20940kb

input:

2 0
861866350 106689920

output:

106689920

result:

ok single line: '106689920'

Test #2:

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

input:

3 0
582295931 120217528 845887275

output:

-1

result:

ok single line: '-1'

Test #3:

score: 0
Accepted
time: 15ms
memory: 22696kb

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: 28ms
memory: 25128kb

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: 51ms
memory: 28972kb

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: 39ms
memory: 27824kb

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: 44ms
memory: 27740kb

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: 37ms
memory: 27348kb

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

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

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: 43ms
memory: 27260kb

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

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

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: 31ms
memory: 27312kb

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: 28ms
memory: 27320kb

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: 28ms
memory: 26396kb

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

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:

456895567

result:

wrong answer 1st lines differ - expected: '456936470', found: '456895567'