QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671396#265. 正则二分图匹配Qingyyx100 ✓2105ms44884kbC++202.5kb2024-10-24 12:13:172024-10-24 12:13:17

Judging History

This is the latest submission verdict.

  • [2024-10-24 12:13:17]
  • Judged
  • Verdict: 100
  • Time: 2105ms
  • Memory: 44884kb
  • [2024-10-24 12:13:17]
  • Submitted

answer

#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 2e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
template <class T = int>inline T read() { T s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline int indi(char* s) { int n = 0; for (s[0] = gc(); !isdigit(s[0]); s[0] = gc()); for (; isdigit(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(auto* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, d;
int to[MAXN], id[MAXN], L[MAXN], R[MAXN];
int stk[MAXN], top;
bool vis[MAXN];
random_device rd;
mt19937_64 rng(rd());
void solve() {
    n = read(), d = read();
    for (int i = 0; i < n * d; ++i)to[i] = read() - 1;
    for (int i = 0; i < n; i++) id[i] = i, R[i] = -1;
    shuffle(id, id + n, rd);
    for (int i = 0; i < n; i++) {
        top = 0;
        int x = id[i];
        while (~x) {
            int y = to[x * d + rng() % d];
            while (R[y] == x) y = to[x * d + rng() % d];
            while (vis[y]) vis[stk[top--]] = 0;
            x = R[y], vis[stk[++top] = y] = 1;
        }
        x = id[i];
        for (int j = 1; j <= top; j++) vis[stk[j]] = 0, swap(x, R[stk[j]]);
    }
    for (int i = 0; i < n; i++) L[R[i]] = i;
    for (int i = 0; i < n; i++) cout << L[i] + 1 << ' ';
}
signed main(signed argc, char const* argv[]) {
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    //=============================================================
    int TxT = 1;
    // TxT = read();
    while (TxT--)
        solve();
    //=============================================================
#ifdef LOCAL
    end :
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 3.0303
Accepted
time: 210ms
memory: 21148kb

input:

200000 1
4860
68405
196988
88061
63179
145556
153543
137408
73529
98133
121426
169157
139971
30468
40561
61417
2377
128946
78342
104898
53132
19812
6001
76501
144382
28176
104732
93137
81527
47685
16750
178443
30278
34394
36927
144836
113402
150495
198662
154016
49033
63788
118907
17990
25923
171718...

output:

4860 68405 196988 88061 63179 145556 153543 137408 73529 98133 121426 169157 139971 30468 40561 61417 2377 128946 78342 104898 53132 19812 6001 76501 144382 28176 104732 93137 81527 47685 16750 178443 30278 34394 36927 144836 113402 150495 198662 154016 49033 63788 118907 17990 25923 171718 199418 8...

result:

ok a perfect matching

Test #2:

score: 3.0303
Accepted
time: 120ms
memory: 18268kb

input:

100000 2
38701 64233
21385 98890
44018 45182
4039 81322
19092 98375
6549 69934
60546 82625
61820 88847
80625 98712
6227 9161
47457 91129
69077 71917
48385 81391
40048 85262
10964 28517
55941 72848
35865 43668
14735 97999
79332 90768
40710 94535
77099 85283
43429 80203
21562 48738
62878 80027
1251 44...

output:

64233 98890 45182 4039 98375 69934 82625 61820 98712 9161 91129 71917 81391 40048 28517 55941 43668 14735 90768 94535 77099 43429 48738 80027 1251 95683 3554 82308 74040 41400 48086 62117 40713 28633 1726 12755 36642 84843 96458 31819 12260 77366 78075 81570 68967 67263 43515 96170 90595 96142 38284...

result:

ok a perfect matching

Test #3:

score: 3.0303
Accepted
time: 83ms
memory: 18056kb

input:

66666 3
2865 7709 21957
3002 30528 66049
3259 33642 55999
27855 64335 65310
3379 7925 44323
21726 35131 35446
20806 52528 63257
6408 27039 50557
15771 37822 58917
29235 34506 64074
9789 11376 42730
6007 25251 46717
4858 28813 65939
10460 37494 38602
18356 26954 46940
20154 50645 56311
10095 17174 34...

output:

2865 3002 3259 65310 3379 21726 52528 6408 37822 34506 11376 25251 65939 10460 18356 50645 17174 27246 32779 36214 57776 31765 23515 24590 18532 46800 12346 34086 60419 27892 4713 52945 52942 18006 44265 32676 17419 52012 63154 19284 12216 10239 47574 37820 16498 35787 28826 3746 62477 6160 12914 60...

result:

ok a perfect matching

Test #4:

score: 3.0303
Accepted
time: 10ms
memory: 18004kb

input:

20000 10
4453 4938 7489 8143 8851 14086 15777 15856 19810 19994
1101 1589 3045 4999 7145 8862 10949 13906 14209 19253
813 936 1987 3395 4231 9971 10028 10087 13816 17859
295 1543 6587 10106 10944 11046 12258 14673 15335 16861
1299 1466 3906 4352 4908 5370 12314 15702 16937 18602
1625 1957 1971 4818 ...

output:

7489 19253 10028 10944 18602 16496 3726 9340 7283 19489 9401 17944 13980 16885 16539 19277 15415 18424 17054 10317 12781 17098 10940 18160 18643 793 1470 1713 15531 16018 6424 1613 10648 16693 9986 1593 3297 13176 4255 2391 18245 13940 2423 6491 9912 3601 3411 2167 3654 3320 5179 14015 10527 2253 18...

result:

ok a perfect matching

Test #5:

score: 3.0303
Accepted
time: 10ms
memory: 18004kb

input:

10000 20
798 829 835 1016 1195 2218 3476 3501 3863 4059 4073 4687 6721 7114 7148 7348 8500 8532 8775 9158
541 778 816 1906 2526 2578 3326 3607 4160 4522 4820 6306 6687 6923 8549 8695 8985 9347 9553 9994
159 382 543 648 1201 1650 2562 3014 3235 3376 3505 3876 5740 6798 7148 7580 8320 8525 9424 9521
2...

output:

8532 4522 6798 3875 1201 9482 923 116 702 820 2501 4834 5115 5362 8675 6612 9268 7930 9633 9858 4521 4590 1714 3504 339 234 6248 1064 452 9717 4308 8432 6958 7356 9701 3354 9151 2396 8430 4684 3650 1910 4606 3242 2603 7917 1925 357 5608 173 2965 1750 9695 6304 9803 6521 3038 3030 6298 1578 8531 1833...

result:

ok a perfect matching

Test #6:

score: 3.0303
Accepted
time: 7ms
memory: 18780kb

input:

4000 50
330 432 487 676 726 738 833 937 949 954 975 994 1032 1051 1099 1132 1183 1346 1547 1566 1617 1720 1721 1774 1803 1980 2193 2328 2350 2413 2426 2587 2691 2792 2976 3021 3066 3119 3171 3477 3484 3533 3577 3605 3618 3731 3803 3874 3918 3994
28 75 214 265 313 319 335 366 403 556 714 804 924 938 ...

output:

3119 265 1154 2825 3747 876 2488 1122 2990 1782 2202 2098 151 614 707 2561 322 2437 1986 3473 2112 2654 396 1987 1603 2843 2885 3630 283 2452 3443 1117 1910 992 994 3260 3762 352 1202 1792 2557 192 418 783 744 720 494 126 968 1531 2308 3731 3919 695 1446 1866 2565 700 1297 927 917 1317 3493 743 947 ...

result:

ok a perfect matching

Test #7:

score: 3.0303
Accepted
time: 2ms
memory: 18644kb

input:

2000 100
4 12 54 56 69 85 113 123 128 183 207 209 212 212 247 249 310 330 347 377 403 409 421 435 484 500 504 526 540 556 571 578 589 648 648 694 727 732 732 790 797 838 871 880 889 950 973 1018 1018 1025 1063 1109 1116 1145 1197 1230 1239 1258 1266 1268 1284 1304 1307 1376 1383 1386 1395 1404 1412 ...

output:

526 1900 1529 1383 1211 666 773 1577 1178 845 1085 1495 1181 1953 683 884 576 469 1261 47 1870 1886 1255 292 106 1110 1449 1476 508 1350 448 974 366 1256 1486 541 1756 1489 1747 68 752 1589 1826 733 1792 1615 1981 1708 506 1534 638 1005 780 392 10 601 431 1701 1878 1319 1750 1212 1095 181 1406 152 1...

result:

ok a perfect matching

Test #8:

score: 3.0303
Accepted
time: 0ms
memory: 17984kb

input:

1000 200
3 9 11 14 28 33 35 38 44 63 74 83 83 95 100 104 106 106 109 118 128 131 132 132 140 142 143 144 145 145 145 149 150 155 161 166 167 172 173 174 174 175 183 190 194 198 201 201 203 203 204 215 217 223 225 242 248 258 267 269 272 272 275 278 281 293 297 299 318 320 334 339 343 344 344 347 348...

output:

994 876 937 513 671 313 97 735 766 785 64 743 492 197 666 504 319 171 287 959 141 353 349 634 920 439 973 45 256 500 261 814 827 942 809 281 965 813 422 918 681 245 820 244 40 563 4 530 398 285 512 161 964 925 818 367 49 957 950 225 333 391 210 146 647 37 28 272 884 680 289 292 346 178 564 84 402 88...

result:

ok a perfect matching

Test #9:

score: 3.0303
Accepted
time: 0ms
memory: 20264kb

input:

666 300
1 1 5 5 11 13 13 14 19 23 25 25 25 28 31 31 31 34 36 36 37 41 44 44 45 46 52 54 55 57 58 59 61 62 65 66 67 68 71 72 75 81 81 83 84 84 87 90 92 93 93 94 95 99 99 101 103 103 105 115 115 116 117 117 120 120 123 126 131 131 136 137 142 144 151 152 161 161 162 167 169 169 169 173 177 178 184 188...

output:

332 276 661 20 528 635 161 164 526 97 101 359 357 374 18 286 566 406 331 297 531 290 13 146 135 426 138 272 360 573 198 197 40 653 602 91 300 537 87 505 16 347 187 24 260 92 250 313 298 652 231 261 656 533 507 655 340 442 35 580 524 213 281 246 649 45 289 643 301 314 128 65 495 555 476 102 183 628 9...

result:

ok a perfect matching

Test #10:

score: 3.0303
Accepted
time: 0ms
memory: 17988kb

input:

20 10000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

8 18 2 7 11 6 13 10 17 19 16 4 3 9 5 14 12 20 1 15 

result:

ok a perfect matching

Test #11:

score: 3.0303
Accepted
time: 3ms
memory: 18240kb

input:

2 100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

2 1 

result:

ok a perfect matching

Test #12:

score: 3.0303
Accepted
time: 0ms
memory: 18048kb

input:

1 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1 

result:

ok a perfect matching

Test #13:

score: 3.0303
Accepted
time: 2105ms
memory: 44884kb

input:

2000000 1
387507
1430778
218094
455064
807442
1582214
917699
1655968
1778462
772123
268962
996042
374054
1403419
1624814
36042
813077
1143919
1473390
817258
501378
1317855
1248063
1909613
1978084
1094998
60629
101651
272496
1610999
1051528
859247
300198
1994497
245332
761294
866191
549873
1162726
40...

output:

387507 1430778 218094 455064 807442 1582214 917699 1655968 1778462 772123 268962 996042 374054 1403419 1624814 36042 813077 1143919 1473390 817258 501378 1317855 1248063 1909613 1978084 1094998 60629 101651 272496 1610999 1051528 859247 300198 1994497 245332 761294 866191 549873 1162726 403056 39135...

result:

ok a perfect matching

Test #14:

score: 3.0303
Accepted
time: 1442ms
memory: 36500kb

input:

1000000 2
199363 754950
76613 628921
173375 900947
609231 802901
21413 217216
740983 755278
357523 781326
137929 439975
210831 550908
427758 764273
137762 254720
568822 871564
588642 836016
31686 707140
266427 566788
321499 905137
189618 726558
616699 630104
54080 766176
117957 586699
695703 987876
...

output:

754950 628921 173375 609231 217216 755278 357523 439975 550908 764273 137762 568822 588642 707140 566788 905137 189618 630104 766176 586699 987876 178663 973796 94468 38853 24371 227766 798274 81723 280560 138177 155987 749454 322629 736226 232092 398160 796647 66848 300748 137995 726017 248166 5841...

result:

ok a perfect matching

Test #15:

score: 3.0303
Accepted
time: 794ms
memory: 30084kb

input:

500000 4
38271 230013 254334 270640
41039 61228 344559 469434
263792 361339 441492 465652
55336 132032 276847 276901
14837 141419 213180 305018
165556 253636 256179 468748
49634 114442 197634 309934
26445 46027 179574 201044
141683 182112 384092 450681
260438 356066 389831 392443
247869 290124 41698...

output:

270640 41039 263792 55336 213180 468748 309934 201044 450681 389831 290124 290882 191935 184280 140596 157628 481256 492497 475326 187536 230363 473670 54300 161626 23604 263970 32429 297951 415559 55048 85438 362915 310947 325869 414682 115932 4677 73284 246279 462026 283356 220992 20598 451720 434...

result:

ok a perfect matching

Test #16:

score: 3.0303
Accepted
time: 434ms
memory: 27364kb

input:

250000 8
2631 146917 164090 180005 186384 187359 209401 239796
19897 50857 57851 99955 119125 130482 197939 211046
61602 69725 125661 151789 152333 170938 191567 244630
28250 88386 126306 156434 209401 213742 236654 239399
4661 8624 39270 85312 106345 123219 179670 231814
3378 4520 37957 90740 10263...

output:

187359 119125 170938 239399 123219 4520 49116 150679 142572 17167 136406 128774 224245 66272 119397 128428 213987 70703 144437 97233 218244 71443 209750 167208 171785 90018 53554 95303 165348 205400 113436 46350 115998 104781 191397 7397 72715 153748 191852 53285 225314 103096 20212 150524 123881 23...

result:

ok a perfect matching

Test #17:

score: 3.0303
Accepted
time: 198ms
memory: 25788kb

input:

125000 16
1740 2837 3454 4468 4752 8259 17820 35622 53227 59127 62189 70804 104178 107139 112956 115071
4672 4917 5273 8630 19872 29772 34538 45649 48808 70653 77894 79629 89198 91989 111456 112385
10180 31425 32554 33836 40036 42641 68031 69244 69346 89583 91384 91749 102500 118132 118521 120404
98...

output:

53227 91989 102500 69229 81700 30637 108981 92988 106775 105537 89527 60270 57928 124231 112215 105218 67402 48107 50852 43227 74810 114765 63064 77567 79151 82396 84616 71961 49639 40678 19258 76425 57462 100345 83833 4435 88902 53447 118376 22645 31502 2472 2908 37595 19071 110173 62069 46610 9625...

result:

ok a perfect matching

Test #18:

score: 3.0303
Accepted
time: 77ms
memory: 25772kb

input:

62500 32
3835 4069 6664 9493 9882 11044 12096 13503 17277 21165 21387 21724 22795 27921 28532 30505 31535 32452 33959 39348 40644 42723 43420 44352 46706 48636 52153 56846 58062 58696 59340 62159
270 3267 5060 9255 11830 12242 12358 12423 12466 14286 16368 17387 23582 23668 23942 24884 26776 31524 3...

output:

21165 37722 29897 12524 46032 61021 25991 25855 49822 35512 19839 28992 37743 54319 6249 19648 39787 28023 49560 21949 46327 12754 37950 37166 10906 31072 14840 43826 54479 30602 45087 14114 48406 52838 24965 964 28740 33718 5629 43156 3447 37983 1973 33784 33437 19960 41532 58032 38780 54984 48237 ...

result:

ok a perfect matching

Test #19:

score: 3.0303
Accepted
time: 19ms
memory: 24048kb

input:

15625 128
51 164 216 257 339 348 735 949 1178 1284 1664 1680 1707 1781 1809 1887 2034 2323 2389 2460 2631 2889 3166 3213 3234 3270 3336 3337 3426 3430 3488 3622 3637 3764 3813 3873 3932 4215 4267 4299 4364 4501 4643 4786 5012 5030 5070 5085 5119 5187 5317 5400 5459 5730 5860 5917 6187 6410 6795 7233...

output:

4299 8697 4153 7176 4602 13447 11808 6412 14699 4507 5858 12480 9750 3097 9219 977 11104 11173 11059 13472 7436 8414 3789 14322 3090 2294 6240 13349 15127 2978 4232 2367 12784 15144 7604 4884 664 10938 10234 9368 12425 7925 6399 1314 15151 3932 7909 120 2527 11546 13414 8656 13272 12243 8433 9420 10...

result:

ok a perfect matching

Test #20:

score: 3.0303
Accepted
time: 13ms
memory: 24124kb

input:

1953 1024
1 2 4 6 8 8 9 13 15 15 17 27 31 32 34 35 35 37 38 40 40 42 45 49 50 51 52 57 61 62 63 64 67 69 70 73 79 82 82 83 86 90 91 92 94 100 101 106 106 107 109 111 113 114 116 116 118 120 120 125 127 132 140 147 148 148 153 156 158 159 159 163 165 165 168 169 169 170 170 171 172 173 174 175 176 17...

output:

646 1165 1064 203 401 641 952 333 488 1369 602 980 411 1858 876 213 1794 880 1237 1694 908 140 1309 1538 1830 418 142 1015 1622 1380 567 150 1197 525 1807 906 1895 1186 1403 741 1617 1259 569 445 1078 1584 1017 138 1506 1067 731 237 1866 89 1262 1929 954 845 413 1668 1462 1746 672 1379 1058 916 1712...

result:

ok a perfect matching

Test #21:

score: 3.0303
Accepted
time: 8ms
memory: 24152kb

input:

244 8192
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5...

output:

6 215 145 17 143 43 42 243 103 123 113 122 160 153 170 30 208 105 167 144 200 115 166 76 222 130 219 126 25 64 175 83 37 152 134 53 155 214 233 187 176 195 132 35 189 54 181 151 104 51 98 101 238 32 141 117 93 12 114 210 192 107 204 109 227 221 44 49 162 178 159 18 111 90 183 177 147 171 45 99 55 22...

result:

ok a perfect matching

Test #22:

score: 3.0303
Accepted
time: 3ms
memory: 24000kb

input:

30 65536
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

23 27 15 1 13 24 12 2 18 30 21 20 19 26 10 28 25 6 5 16 14 22 7 8 9 17 29 3 11 4 

result:

ok a perfect matching

Test #23:

score: 3.0303
Accepted
time: 4ms
memory: 24588kb

input:

3 524288
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1 2 3 

result:

ok a perfect matching

Test #24:

score: 3.0303
Accepted
time: 1097ms
memory: 35800kb

input:

666666 3
3206 64240 199437
251202 414004 479216
133162 349551 525296
267125 278228 385799
255071 266873 648864
203529 309604 516958
227388 593079 647002
98211 414478 512085
200513 287454 395398
81231 139438 488811
180775 408644 487195
74579 149392 515012
466358 589635 620337
159618 186366 345229
255...

output:

64240 479216 525296 267125 255071 203529 227388 98211 200513 81231 408644 149392 466358 159618 455975 203276 231281 227367 7842 135998 90374 578479 453716 75664 346689 381924 239426 31353 351294 521357 260268 113852 145895 227431 11376 262668 466198 450386 477197 544112 181409 501288 95016 482586 43...

result:

ok a perfect matching

Test #25:

score: 3.0303
Accepted
time: 305ms
memory: 27216kb

input:

200000 10
2798 8208 22730 66600 119481 122650 156801 175474 177550 185015
9474 33088 52512 58337 89617 108000 129764 138027 167767 186477
2825 26827 51804 54149 80285 86265 97887 107376 141558 147823
19363 43877 45893 65333 88598 97896 108948 116509 131339 153148
33060 35928 44747 76078 78934 99908 ...

output:

185015 138027 147823 88598 35928 101045 118168 134409 159027 91629 128403 33943 145049 196124 32735 9534 175962 107387 171148 165805 123229 51831 29196 24627 2402 169090 20566 73851 180252 31335 93435 194599 39133 141659 186481 38729 17025 175867 122867 128245 172534 49503 114749 19302 52037 28636 2...

result:

ok a perfect matching

Test #26:

score: 3.0303
Accepted
time: 162ms
memory: 22340kb

input:

100000 20
5397 8196 10191 10507 18634 28459 29340 32559 40283 40598 53734 65521 67349 68029 69345 71483 76269 82047 84895 88672
4462 14803 19562 24889 25953 28548 32601 34192 34507 38342 48801 54116 68838 73926 78615 79627 83981 88503 90442 93297
13394 25531 37640 43005 43893 48131 51275 52948 59539...

output:

10507 34192 75892 13891 33550 88183 14047 30358 93991 62795 79982 24175 72988 70099 83162 2822 32110 3478 92572 88667 86371 12203 37456 7828 36453 85133 82810 62732 87972 18561 44195 326 57833 5279 3984 87285 88521 51901 44185 6074 65582 76136 3363 41932 6353 37029 27483 61969 34428 88830 13909 9477...

result:

ok a perfect matching

Test #27:

score: 3.0303
Accepted
time: 50ms
memory: 27616kb

input:

40000 50
230 2074 4290 4458 5074 6272 7009 8092 9278 10651 11049 11356 11594 11916 14215 14942 15654 17392 18351 19069 19367 19408 20099 20658 20846 22407 23012 23933 25542 25551 25843 25941 27453 27611 28243 29369 30209 30972 31099 33489 33788 34810 34829 34849 36245 36571 37309 37983 38974 39485
1...

output:

34829 11600 37889 10060 865 24996 37834 32979 35644 16105 34900 4333 5569 29995 10941 21619 7769 11849 24632 5878 36439 3120 10039 27842 9371 24610 13365 1437 37502 10958 2704 26951 7201 25576 36985 18927 12339 24237 39101 1836 6042 14174 16259 11364 28574 28079 1280 30994 3229 29736 34446 32447 107...

result:

ok a perfect matching

Test #28:

score: 3.0303
Accepted
time: 35ms
memory: 25144kb

input:

20000 100
346 384 416 439 566 781 899 950 1359 1370 1969 2025 2031 2043 2510 2703 3581 3610 3956 3960 3987 4008 4035 4392 4409 4853 5049 5092 5101 5955 6051 6132 6184 6260 6463 6632 6725 6995 7298 8049 8324 8349 8720 9111 9137 9233 9328 9353 9366 9405 9427 9496 9571 9572 9588 9641 9780 9879 10102 10...

output:

6632 10322 18060 5879 18683 532 877 11706 12921 235 465 3353 18270 8976 18023 6259 303 9558 19233 18509 17307 4112 16110 10366 3871 14011 17687 11478 7901 12990 19993 13465 10205 8905 19021 9483 13299 8352 4765 7235 12695 14064 7022 9501 5931 7859 11783 8829 14479 5737 2090 10126 5944 13546 5511 178...

result:

ok a perfect matching

Test #29:

score: 3.0303
Accepted
time: 14ms
memory: 25004kb

input:

6666 300
16 22 93 102 144 171 192 203 255 266 282 288 363 364 371 371 379 394 409 477 495 497 500 515 654 696 706 718 789 797 810 816 826 826 827 833 844 854 911 913 933 980 982 1006 1055 1078 1087 1116 1130 1139 1178 1245 1266 1367 1386 1447 1463 1468 1472 1489 1492 1495 1502 1513 1519 1526 1527 15...

output:

171 3597 2324 925 5231 633 6171 5682 4943 1284 1004 3832 1214 2777 154 879 54 943 4305 503 1481 3032 6146 3575 5557 3579 3739 5341 6328 2254 4746 283 478 5133 59 5614 3277 5321 605 2943 1831 5082 2779 5458 1761 248 1320 5747 3646 2381 2702 6109 5968 4945 4432 4154 472 1812 6262 4863 2329 5331 865 22...

result:

ok a perfect matching

Test #30:

score: 3.0303
Accepted
time: 6ms
memory: 24728kb

input:

2000 1000
2 3 6 14 17 20 23 23 25 25 28 30 32 32 34 36 38 39 40 41 41 42 42 48 52 52 53 54 54 54 56 60 60 60 61 61 66 67 67 68 70 72 80 83 85 86 87 89 89 90 90 91 92 95 96 98 105 108 109 110 110 113 114 116 118 119 122 124 127 130 131 132 133 134 134 135 143 147 149 152 154 156 161 163 163 165 165 1...

output:

1475 365 498 885 1753 143 1018 1857 463 788 299 1918 136 1600 396 1728 1440 715 654 1504 804 181 946 283 1060 1016 855 1777 732 972 1815 914 989 309 1596 120 1297 1642 670 468 522 974 1800 1073 1312 399 1465 311 757 1919 1165 643 1215 358 1202 1633 985 177 780 1820 1013 1055 1339 1760 791 1216 896 1...

result:

ok a perfect matching

Test #31:

score: 3.0303
Accepted
time: 6ms
memory: 25656kb

input:

40 50000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

34 14 7 3 27 28 37 40 25 18 39 17 23 19 4 13 9 33 6 31 38 16 20 32 10 2 22 24 1 8 29 12 11 26 30 15 36 5 21 35 

result:

ok a perfect matching

Test #32:

score: 3.0303
Accepted
time: 10ms
memory: 24624kb

input:

4 500000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1 2 3 4 

result:

ok a perfect matching

Test #33:

score: 3.0303
Accepted
time: 3ms
memory: 25780kb

input:

1 2000000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

1 

result:

ok a perfect matching