QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#437652#8787. Unusual Caseucup-team133AC ✓1129ms53564kbC++236.5kb2024-06-09 14:41:002024-06-09 14:41:01

Judging History

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

  • [2024-06-09 14:41:01]
  • 评测
  • 测评结果:AC
  • 用时:1129ms
  • 内存:53564kb
  • [2024-06-09 14:41:00]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& e : v) {
        is >> e;
    }
    return is;
}

template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    for (std::string_view sep = ""; const auto& e : v) {
        os << std::exchange(sep, " ") << e;
    }
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) {
    return y < x and (x = std::forward<U>(y), true);
}

template <class T, class U = T> bool chmax(T& x, U&& y) {
    return x < y and (x = std::forward<U>(y), true);
}

template <class T> void mkuni(std::vector<T>& v) {
    std::ranges::sort(v);
    auto result = std::ranges::unique(v);
    v.erase(result.begin(), result.end());
}

template <class T> int lwb(const std::vector<T>& v, const T& x) {
    return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}

using ll = long long;

using namespace std;

// https://codeforces.com/blog/entry/90513
namespace hamil {
template <typename T> bool chkmax(T& x, T y) { return x < y ? x = y, true : false; }
template <typename T> bool chkmin(T& x, T y) { return x > y ? x = y, true : false; }
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
#define ll long long
namespace LCT {
vector<vi> ch;
vi fa, rev;
void init(int n) {
    ch.resize(n + 1);
    fa.resize(n + 1);
    rev.resize(n + 1);
    for (int i = 0; i <= n; i++) ch[i].resize(2), ch[i][0] = ch[i][1] = fa[i] = rev[i] = 0;
}
bool isr(int a) { return !(ch[fa[a]][0] == a || ch[fa[a]][1] == a); }
void pushdown(int a) {
    if (rev[a]) {
        rev[ch[a][0]] ^= 1, rev[ch[a][1]] ^= 1;
        swap(ch[a][0], ch[a][1]);
        rev[a] = 0;
    }
}
void push(int a) {
    if (!isr(a)) push(fa[a]);
    pushdown(a);
}
void rotate(int a) {
    int f = fa[a], gf = fa[f];
    int tp = ch[f][1] == a;
    int son = ch[a][tp ^ 1];
    if (!isr(f)) ch[gf][ch[gf][1] == f] = a;
    fa[a] = gf;

    ch[f][tp] = son;
    if (son) fa[son] = f;

    ch[a][tp ^ 1] = f, fa[f] = a;
}
void splay(int a) {
    push(a);
    while (!isr(a)) {
        int f = fa[a], gf = fa[f];
        if (isr(f))
            rotate(a);
        else {
            int t1 = ch[gf][1] == f, t2 = ch[f][1] == a;
            if (t1 == t2)
                rotate(f), rotate(a);
            else
                rotate(a), rotate(a);
        }
    }
}
void access(int a) {
    int pr = a;
    splay(a);
    ch[a][1] = 0;
    while (1) {
        if (!fa[a]) break;
        int u = fa[a];
        splay(u);
        ch[u][1] = a;
        a = u;
    }
    splay(pr);
}
void makeroot(int a) {
    access(a);
    rev[a] ^= 1;
}
void link(int a, int b) {
    makeroot(a);
    fa[a] = b;
}
void cut(int a, int b) {
    makeroot(a);
    access(b);
    fa[a] = 0, ch[b][0] = 0;
}
int fdr(int a) {
    access(a);
    while (1) {
        pushdown(a);
        if (ch[a][0])
            a = ch[a][0];
        else {
            splay(a);
            return a;
        }
    }
}
}  // namespace LCT
vi out, in;
vi work(int n, vector<pi> eg, ll mx_ch = -1) {
    // mx_ch : max number of adding/replacing  default is (n + 100) * (n + 50)
    // n : number of vertices. 1-indexed.
    // eg: vector<pair<int, int> > storing all the edges.
    // return a vector<int> consists of all indices of vertices on the path. return empty list if failed to find one.
    out.resize(n + 1), in.resize(n + 1);
    LCT::init(n);
    for (int i = 0; i <= n; i++) in[i] = out[i] = 0;
    if (mx_ch == -1) mx_ch = 1ll * (n + 100) * (n + 50);  // default
    vector<vi> from(n + 1), to(n + 1);
    for (auto v : eg) from[v.fi].pb(v.se), to[v.se].pb(v.fi);
    unordered_set<int> canin, canout;
    for (int i = 1; i <= n; i++) canin.insert(i), canout.insert(i);
    mt19937 x(chrono::steady_clock::now().time_since_epoch().count());
    int tot = 0;
    while (mx_ch >= 0) {
        //    cout << tot << ' ' << mx_ch << endl;
        vector<pi> eg;
        for (auto v : canout)
            for (auto s : from[v])
                if (in[s] == 0) {
                    assert(canin.count(s));
                    continue;
                } else
                    eg.pb(mp(v, s));
        for (auto v : canin)
            for (auto s : to[v]) eg.pb(mp(s, v));
        shuffle(eg.begin(), eg.end(), x);
        if (eg.size() == 0) break;
        for (auto v : eg) {
            mx_ch--;
            if (in[v.se] && out[v.fi]) continue;
            if (LCT::fdr(v.fi) == LCT::fdr(v.se)) continue;
            if (in[v.se] || out[v.fi])
                if (x() & 1) continue;
            if (!in[v.se] && !out[v.fi]) tot++;
            if (in[v.se]) {
                LCT::cut(in[v.se], v.se);
                canin.insert(v.se);
                canout.insert(in[v.se]);
                out[in[v.se]] = 0;
                in[v.se] = 0;
            }
            if (out[v.fi]) {
                LCT::cut(v.fi, out[v.fi]);
                canin.insert(out[v.fi]);
                canout.insert(v.fi);
                in[out[v.fi]] = 0;
                out[v.fi] = 0;
            }
            LCT::link(v.fi, v.se);
            canin.erase(v.se);
            canout.erase(v.fi);
            in[v.se] = v.fi;
            out[v.fi] = v.se;
        }
        if (tot == n - 1) {
            vi cur;
            for (int i = 1; i <= n; i++)
                if (!in[i]) {
                    int pl = i;
                    while (pl) {
                        cur.pb(pl), pl = out[pl];
                    }
                    break;
                }
            return cur;
        }
    }
    // failed to find a path
    return vi();
}
}  // namespace hamil

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> u(m), v(m);
    for (int i = 0; i < m; i++) cin >> u[i] >> v[i];

    vector<bool> alive(m, true);
    map<pair<int, int>, int> mp;
    for (int i = 0; i < m; i++) mp[{u[i], v[i]}] = mp[{v[i], u[i]}] = i;

    for (; k--;) {
        vector<pair<int, int>> es;
        for (int i = 0; i < m; i++) {
            if (not alive[i]) continue;
            es.emplace_back(u[i], v[i]);
            es.emplace_back(v[i], u[i]);
        }
        auto path = hamil::work(n, es);
        assert(not path.empty());
        cout << path << "\n";
        for (int i = 0; i + 1 < n; i++) {
            assert(mp.count({path[i], path[i + 1]}));
            alive[mp[{path[i], path[i + 1]}]] = false;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 9 2
1 3
1 4
1 5
2 3
2 4
2 5
3 5
4 3
5 4

output:

4 1 3 2 5
2 4 3 5 1

result:

ok OK (n = 5, m = 9)

Test #2:

score: 0
Accepted
time: 1001ms
memory: 51848kb

input:

10000 200000 8
6318 9948
9588 8985
4252 4927
1146 9347
2276 7434
9612 4436
8319 1837
4428 1043
5976 2759
879 1564
7866 4849
2070 5310
8407 156
7306 7766
9100 1576
1181 6122
7790 7065
3235 8877
5661 9718
1555 743
5479 9755
2601 8190
3318 2067
4084 8193
1050 269
64 5504
3416 5041
7169 197
2158 2523
57...

output:

7579 8021 5188 2670 5569 1879 698 3168 5597 1923 3725 301 9878 8816 3717 5027 4543 5627 2044 9495 8495 9869 6351 2119 4937 6547 4735 1054 8088 1688 2528 7811 6229 8622 7831 5818 3402 6307 6774 725 3539 3260 4061 6349 4102 2043 4250 7256 7996 110 9763 6196 3726 2218 2825 2124 862 6076 3921 8093 3691 ...

result:

ok OK (n = 10000, m = 200000)

Test #3:

score: 0
Accepted
time: 1013ms
memory: 53564kb

input:

10000 200000 8
7826 9720
8400 2487
6964 6011
4799 6032
3696 3691
7883 4350
9092 3892
3588 7409
6005 4538
4196 7873
4216 4505
6339 1269
2405 5423
9 7030
8193 7285
5782 2768
5646 4946
4483 6857
3431 9325
4243 488
2435 8371
3067 1462
8592 4932
8581 3147
1394 6751
2499 4977
4806 1190
9652 5059
4075 3454...

output:

525 2971 2720 1826 9408 8857 6233 4156 4104 5868 7574 9609 5687 2188 8104 8013 822 8073 7535 1446 3219 596 6929 6355 8435 9660 250 1751 9785 8799 5962 9139 3178 8689 3599 7020 9852 9970 9955 3593 136 5057 5765 3802 6305 2655 462 3042 6594 7409 6940 359 7334 9590 9177 9617 4831 3839 5922 7938 2627 53...

result:

ok OK (n = 10000, m = 200000)

Test #4:

score: 0
Accepted
time: 1048ms
memory: 52568kb

input:

10000 200000 8
6064 4200
2244 5165
648 6303
9246 8103
4187 7801
761 3539
6105 2254
4471 3158
6006 4452
3580 8120
9391 3711
8752 1014
2511 151
800 2285
5388 3282
4704 8712
5372 5509
6988 6976
9314 9056
2225 9256
8567 3853
4135 3386
9688 1467
7287 5856
8107 7114
2385 3663
2991 2969
3746 7352
8828 6735...

output:

887 7837 6800 2493 6873 6600 9818 1855 690 5652 1171 1384 7495 2664 6627 9871 1508 7763 9508 8074 5904 1286 8470 8829 4191 8119 6366 3061 3359 6639 5140 431 9198 4808 7124 5251 6900 5301 351 7502 6134 3447 8817 4939 2957 1590 5725 5502 4338 4631 9968 5556 2329 6048 5526 5572 9919 2439 2265 4719 9710...

result:

ok OK (n = 10000, m = 200000)

Test #5:

score: 0
Accepted
time: 1049ms
memory: 51892kb

input:

10000 200000 8
1034 3387
1120 7020
5302 5802
4487 5560
3749 9763
8246 2002
9358 6922
7077 8289
5976 2501
9030 2306
3390 2468
9307 4546
8724 4342
9679 3531
684 9564
7946 3956
6968 8754
748 9234
3310 8909
5500 7046
3874 6201
5806 3962
6604 1672
203 6318
1189 1358
9723 1561
7970 380
9450 7078
6420 2366...

output:

3448 8966 4303 5964 6218 4727 8664 6850 9128 8848 9713 5025 7511 6540 912 386 3311 1396 6530 7268 1362 3017 6839 3540 9458 639 1469 4555 3284 2168 7983 6652 8821 7665 7230 6001 1056 4860 2735 4352 1954 6676 7494 5715 9097 860 7993 9331 1942 3737 4435 7977 9594 4108 452 6416 3007 1840 2796 562 6987 5...

result:

ok OK (n = 10000, m = 200000)

Test #6:

score: 0
Accepted
time: 1011ms
memory: 51016kb

input:

10000 200000 8
2734 7281
5027 8050
927 4507
523 8404
2382 9578
337 9740
8851 7897
1407 2803
5918 8684
547 430
6215 775
8004 1864
1045 7995
6645 767
4082 6133
5510 8499
433 4681
5763 3631
5419 8885
4068 3859
8356 5416
8078 3190
9342 5547
7329 4533
639 9483
4511 8673
9744 3422
6765 4236
6849 346
2288 ...

output:

3061 9315 2170 9683 9208 2906 1138 6915 588 6050 7184 7962 3351 4874 9219 7135 7924 1181 7887 5541 9309 7390 3592 6259 417 5032 2333 8531 1357 1809 7126 158 1541 9997 4707 6730 7022 5943 9037 1704 7426 294 37 8929 9651 5641 666 1738 4900 7017 2121 8145 8559 3138 9441 4196 6208 2816 9697 7645 7234 78...

result:

ok OK (n = 10000, m = 200000)

Test #7:

score: 0
Accepted
time: 1016ms
memory: 53552kb

input:

10000 200000 8
1166 5882
3966 8257
7523 2420
7353 6633
87 7247
7035 6751
4585 5179
7460 6699
5829 3002
8131 2493
7864 8632
4845 2969
9472 1110
1698 3993
5582 2988
7395 2341
5768 3290
2034 167
5642 8983
7929 9694
2014 1497
952 1069
7900 3092
8663 502
6458 1489
6751 4998
8312 2094
5690 8825
115 676
62...

output:

9489 557 1738 2648 3918 8960 1764 5778 6429 5070 5271 7867 3235 89 190 2431 9463 198 8572 4470 3915 3561 2566 5761 7399 6517 9593 7293 408 197 7939 2269 3619 5496 3623 9815 1286 3207 7863 3765 1048 6171 9334 2308 1946 8291 588 6075 5241 5555 3296 5547 3163 8870 8010 9371 9158 3740 6931 6613 1835 152...

result:

ok OK (n = 10000, m = 200000)

Test #8:

score: 0
Accepted
time: 993ms
memory: 51512kb

input:

10000 200000 8
6328 9191
7937 7640
5090 9539
4977 248
6863 2768
8341 3037
6559 8768
5237 9978
5712 5454
1782 8494
8338 6040
9828 7861
4008 3687
4839 3210
5183 130
3601 5482
2972 4581
9560 8842
3978 9205
7084 4551
4847 4445
4428 7601
2280 4306
4207 4225
8646 7376
6443 536
3674 6398
6226 847
6219 3356...

output:

7877 1669 7049 1092 3546 9157 4152 3204 2004 4747 2968 7270 2652 7782 5627 4323 6919 8260 1931 518 511 8131 7410 5248 4201 7019 3585 6759 9705 9683 2505 8424 2300 1135 919 2834 2752 4951 5129 4515 5386 9654 3480 7925 4430 8596 8015 5151 286 5230 3662 8096 4143 1907 7404 1071 6755 8863 4315 2141 5458...

result:

ok OK (n = 10000, m = 200000)

Test #9:

score: 0
Accepted
time: 974ms
memory: 50364kb

input:

10000 200000 8
8222 7206
6939 6199
3627 5866
3396 9250
2710 6141
4253 8597
4773 8663
4738 2640
5564 6042
1500 8433
7637 2998
2954 6540
4650 5727
6068 8417
2885 7557
4129 7922
2046 8554
8343 9655
428 9550
1531 8431
6855 4259
8506 2784
2481 9190
3961 5701
7203 7144
3585 5286
5830 6332
8372 300
5160 83...

output:

7898 2904 5711 2406 6331 2929 7320 9247 4026 6300 3529 3331 4419 3988 6877 6237 1375 3376 8964 2121 2906 6056 8345 6458 7985 7738 2351 8030 2098 6341 9966 9094 4543 8480 6299 7642 3951 8993 7805 1448 8439 2957 4625 9303 9314 13 3912 1846 3350 8106 6055 464 4116 8566 8163 3991 4958 3823 1558 7746 275...

result:

ok OK (n = 10000, m = 200000)

Test #10:

score: 0
Accepted
time: 1051ms
memory: 53252kb

input:

10000 200000 8
6846 9929
974 3935
3136 1399
2610 3637
7628 7368
4772 3431
9227 4865
5962 4684
5388 4763
7285 2311
5760 9506
4223 9005
1401 7229
5384 9615
8690 5272
8977 9661
2990 5210
8380 2608
4990 18
1272 1334
8039 940
3186 6620
8503 7744
7924 4930
2128 794
8179 9250
4781 1898
2129 7185
6939 5764
...

output:

6810 263 821 3432 5058 4186 3941 7714 3365 7922 6072 8170 5114 1408 550 3190 2450 5826 2496 8291 968 7155 7438 1790 4344 8652 3199 4421 7047 2836 6235 4160 6089 3387 5981 4383 4069 1086 9714 3805 9766 2924 79 2263 2670 7379 9959 8651 5710 1192 2603 537 6650 9094 2549 4827 9428 8313 780 8900 8719 748...

result:

ok OK (n = 10000, m = 200000)

Test #11:

score: 0
Accepted
time: 1039ms
memory: 53420kb

input:

10000 200000 8
2202 7359
40 846
3615 6140
2618 3411
1618 6447
9897 7539
9921 7374
8909 6111
5182 1620
9136 127
2709 5565
3635 5257
4258 8192
2787 6804
2596 3272
8146 700
5803 4547
9673 7699
7666 608
6306 3259
8398 4487
8468 9107
347 9968
6096 1913
3422 8324
225 2426
526 3095
7496 1502
1556 5493
1173...

output:

9445 6705 9400 4702 3992 2690 2138 4187 5729 1549 939 1660 559 6682 7887 4169 5378 7031 4888 360 4442 8616 3914 5100 7635 7921 8300 3074 4483 940 5532 9934 9920 5445 140 9715 2340 5753 9031 9459 4865 796 9627 4784 5162 4359 9856 5222 6063 3160 2217 3826 5376 891 1821 5724 5946 5482 1044 6787 398 233...

result:

ok OK (n = 10000, m = 200000)

Test #12:

score: 0
Accepted
time: 1053ms
memory: 52544kb

input:

10000 200000 8
4288 9496
4137 6934
5065 87
3420 8570
4679 3379
9630 921
6856 6189
3580 6921
4946 6611
7054 1882
8482 1173
1189 5296
3223 8618
8278 9983
4603 1559
1637 1037
487 6567
2222 4930
8456 1322
6633 4206
7932 4900
4352 246
8011 5862
8478 6650
1085 9736
9721 4816
3066 9922
4474 3251
9010 7571
...

output:

1568 5186 806 333 5451 2551 5920 6563 7998 4533 2569 4984 1476 8155 4526 8768 4321 4263 5471 5963 5520 9777 9667 1619 1678 5838 4077 283 4446 7983 1168 9068 1962 5794 7677 8288 3286 3533 6041 9335 7064 305 3507 8257 3687 4175 5044 9859 9191 6278 2974 3036 9260 6617 4581 1751 8751 5939 9802 5354 6314...

result:

ok OK (n = 10000, m = 200000)

Test #13:

score: 0
Accepted
time: 1065ms
memory: 52944kb

input:

10000 200000 8
3105 6341
3267 2198
7486 3241
5017 9116
6811 8164
3970 3578
30 1311
9975 7113
4681 9737
1039 7576
3081 6333
6886 9121
8295 8507
1857 9152
4712 132
9449 674
7039 1268
6027 4299
7358 2158
2254 4176
6642 2180
838 38
1497 5426
5069 9140
5117 5029
6669 6418
2399 2381
3063 2432
9302 1999
61...

output:

7797 7782 7925 9384 4252 8339 75 8089 133 5458 4405 1687 7340 1815 7531 5924 4404 1719 8154 751 1706 4243 5619 5205 440 8778 146 9102 9960 8770 1398 3377 4004 6828 3666 8019 5666 3756 6149 2244 6488 7937 6537 357 1847 4763 3189 1133 138 9518 2676 2205 2420 1486 7206 2656 447 3195 2513 380 3909 6496 ...

result:

ok OK (n = 10000, m = 200000)

Test #14:

score: 0
Accepted
time: 1011ms
memory: 51656kb

input:

10000 200000 8
8654 7892
7428 6639
878 5603
7408 5048
8014 802
2916 5509
9445 2740
8092 6688
4386 998
1091 7207
6504 1042
726 6733
9475 7857
3523 4312
2923 8991
1582 9609
5462 8652
1087 5808
4374 3117
3167 3169
4526 6326
7925 8481
804 8660
5869 9384
5517 4202
1069 7233
8527 470
3262 9045
2431 8777
5...

output:

2555 8408 3138 5502 1058 5281 2902 370 4665 7780 3667 4519 5566 4481 5493 704 2424 848 9252 1706 7217 231 3858 2666 5035 5266 8516 555 2216 5998 4122 6093 9351 5060 8481 9630 3895 8567 2981 2599 1040 7572 8656 5421 6612 4546 2766 5701 7224 731 4078 874 4376 1170 8432 2427 3143 4700 8446 5347 8043 87...

result:

ok OK (n = 10000, m = 200000)

Test #15:

score: 0
Accepted
time: 1040ms
memory: 50472kb

input:

10000 200000 8
933 4151
6621 255
5240 7171
594 6365
8289 1293
6469 6714
5100 476
7934 5646
4062 393
7210 778
8752 5302
2709 8132
6762 6670
3277 5462
9235 8137
8036 7844
5754 8718
7402 9455
9503 4199
9374 1184
1587 7339
5615 5576
5932 5563
879 7381
2286 7257
2919 7262
1450 4191
5071 3090
8398 7904
28...

output:

7502 6300 379 8779 4041 3571 971 711 499 4342 7334 2981 8494 8082 4428 7386 7152 9462 9836 6198 6941 3034 1946 2807 1325 2158 7013 7747 2347 3203 9364 8949 1792 4362 4473 317 9926 7271 2244 3782 6449 4015 9358 5802 6618 1381 6822 9155 2495 4835 6126 7801 3645 4669 940 6177 8034 6307 7228 3196 3468 9...

result:

ok OK (n = 10000, m = 200000)

Test #16:

score: 0
Accepted
time: 1005ms
memory: 52644kb

input:

10000 200000 8
9943 5117
846 3048
573 7946
4574 3069
7634 9636
4629 7193
6995 4518
9499 3986
3709 7923
9395 8286
9824 9113
2834 3317
156 4944
1118 2603
3649 7569
8811 5378
7915 1466
4973 5241
2746 5405
874 8222
7822 5218
3907 1322
6881 6137
98 3131
5423 4193
2221 6503
1167 3542
8491 4566
7202 9381
8...

output:

808 840 1410 7575 6217 4636 9260 6790 6998 6244 8909 6521 9718 892 6629 3598 8598 1536 6786 9896 6111 9508 7413 8329 5596 1937 8178 7120 5398 8271 352 163 1925 1518 1763 7895 9731 2960 1480 7515 2341 9308 3693 6837 4142 498 1959 2957 4867 9091 9252 516 8845 9414 9757 4150 3056 7511 7585 9616 7291 69...

result:

ok OK (n = 10000, m = 200000)

Test #17:

score: 0
Accepted
time: 1112ms
memory: 52684kb

input:

10000 200000 8
5685 790
102 5017
6877 7928
9348 5159
6051 5832
7396 6946
5130 4867
2787 1709
3325 3587
7648 9733
9722 2473
1102 2289
9658 2681
7046 5735
6164 7288
3907 2211
1947 6896
3800 3166
4102 6733
7667 4282
3233 9964
2800 5721
3651 380
3526 6635
4930 5010
8974 4957
7678 8525
3522 3474
8844 320...

output:

5476 9124 2088 3979 4863 5031 2271 3854 6058 2832 5457 544 9273 2403 9226 6375 8866 1528 4077 1568 3345 1698 8615 1952 4865 89 6861 5825 1499 9983 7980 137 8234 5496 807 5729 413 7381 6344 3835 7746 8838 4716 9540 5797 1665 3976 4766 6216 6818 7172 9139 8368 5360 7075 6932 5767 1812 8483 7000 7620 2...

result:

ok OK (n = 10000, m = 200000)

Test #18:

score: 0
Accepted
time: 1056ms
memory: 52572kb

input:

10000 200000 8
8157 1170
4391 6162
4152 7117
4917 2635
3540 9882
4770 5974
9506 1523
7799 8814
2913 7387
1967 5119
8444 5384
7513 5048
5267 9880
1062 4857
6781 7292
3324 8343
7848 5008
3882 3230
3571 8184
9753 9364
7819 1576
2296 8772
6243 8293
1164 7893
805 9708
3179 2624
983 9138
163 9815
3323 938...

output:

4268 1476 6176 6669 5776 1056 6064 3233 6207 8902 200 4965 7338 830 4848 1501 5236 5371 1041 1515 5847 6473 2230 9806 3648 3656 4682 906 9602 1576 7145 284 8252 2965 5329 740 182 5074 2697 3044 3245 4955 8144 108 2418 1215 5498 8876 5611 9290 8070 9431 768 7865 2110 603 8285 3225 7218 5388 5624 5565...

result:

ok OK (n = 10000, m = 200000)

Test #19:

score: 0
Accepted
time: 1074ms
memory: 52612kb

input:

10000 200000 8
7360 6258
3711 6484
2398 5513
1280 5497
99 1783
6751 4276
121 4485
4535 5302
2471 9321
2353 4443
5992 7845
2067 1594
6983 6541
3166 9969
5499 7584
7063 3774
5618 5802
5220 5433
1153 9758
7132 3469
1580 55
2393 474
4655 9876
3012 6904
3048 8287
4835 9504
1083 5383
8414 3587
640 7909
12...

output:

5387 6842 9270 8305 7522 6763 9137 2347 2739 3822 4934 3854 6116 194 3153 9572 5310 6837 5066 6924 3720 9512 5836 4853 2707 416 7140 9437 2936 3685 8857 3174 7846 2237 9700 9529 143 9196 5558 6876 6147 3002 2222 1310 5263 7511 3092 6947 8583 5104 1937 7289 588 7506 4900 9893 6571 6962 8395 8087 6228...

result:

ok OK (n = 10000, m = 200000)

Test #20:

score: 0
Accepted
time: 1129ms
memory: 52940kb

input:

10000 200000 8
3294 6053
8062 5981
1615 3116
8438 3745
5730 1538
3338 1852
6977 3755
2994 1173
1999 9389
8805 7705
2364 9857
4763 1926
4807 2665
3357 1072
2320 8161
5122 8504
5259 9278
7813 9775
6849 1454
9805 6597
4517 5400
3093 829
8889 5129
9068 3669
1661 747
3942 5597
7977 7258
8276 4791
794 878...

output:

384 2741 586 4788 4837 9595 8208 6844 7867 6895 5805 7695 3682 9200 9401 7767 9122 1478 9312 9109 2822 269 6091 6893 6039 5482 2152 5436 172 1158 2307 1351 517 7188 2852 9342 3410 3639 2626 6912 8948 7743 8788 6133 3843 1096 8913 564 9268 3474 8142 5696 3250 7895 9030 1552 9980 2781 5346 4367 37 97 ...

result:

ok OK (n = 10000, m = 200000)

Test #21:

score: 0
Accepted
time: 1049ms
memory: 51624kb

input:

10000 200000 8
5960 554
7446 4655
1802 9926
6390 7380
432 9145
4532 8702
73 9330
3176 6426
1498 7593
1325 4906
7561 1419
5603 6045
8738 8250
1636 8165
7241 9025
7503 2533
6769 5436
1662 6255
658 3274
7771 8747
6629 7611
4394 9835
8944 4052
9334 8187
6642 7088
500 903
1665 4765
9749 3427
3786 2010
29...

output:

3054 3340 7987 4841 4138 7813 857 4201 422 3038 5232 3448 3715 5279 9878 2168 7371 3434 7954 5638 3481 8082 2061 7359 1898 6233 8847 9241 922 4002 528 1554 3201 6570 7058 2744 1984 1053 9143 8200 7785 2796 8915 6599 6288 5411 9868 4030 2428 1846 6208 8365 4459 2070 7397 6521 2734 7080 5734 662 4695 ...

result:

ok OK (n = 10000, m = 200000)

Test #22:

score: 0
Accepted
time: 1002ms
memory: 51768kb

input:

10000 200000 8
5356 9763
1861 2505
2960 5943
5137 6400
4205 4606
334 4826
9409 1213
5082 1062
968 3931
9911 6045
1583 2531
4585 3950
8777 3298
8002 1249
265 175
4205 5862
148 4277
6766 4875
2580 5217
1030 9919
7916 6689
6297 7493
4820 6644
3810 458
7992 7311
4510 5422
2148 7902
2832 9495
9616 7585
5...

output:

7081 2028 3734 3102 2103 6974 4910 835 3824 4187 8729 786 2364 4921 2735 7226 3200 8190 7794 8748 19 9802 6485 964 9139 5904 4286 4752 4657 25 7779 5815 6223 3284 3089 7445 9366 9145 774 8435 9414 1786 6211 4111 8843 9878 6457 4323 4173 6561 6766 3696 3323 9974 2250 7811 2870 7151 1774 5807 3500 551...

result:

ok OK (n = 10000, m = 200000)

Test #23:

score: 0
Accepted
time: 1121ms
memory: 53040kb

input:

10000 200000 8
1483 3680
1308 9532
5089 1166
4678 806
7049 7919
742 225
4985 9402
8711 5081
408 8403
4565 1123
4429 3193
1709 5643
4923 7808
2456 324
1389 1611
5228 8489
5397 5799
3126 5633
2616 7282
9582 114
8379 2634
8802 3804
6517 2907
2495 483
5711 1414
5972 9154
9425 6671
7526 2994
8283 5509
64...

output:

3826 490 4215 9284 2821 8160 5717 8978 5281 1574 1309 3715 7491 3411 2793 1361 474 3318 5252 2807 5224 5613 499 3175 4858 8093 3545 7944 7425 273 5657 7899 9855 9516 1444 7082 6859 5365 985 343 7187 791 5951 8100 8748 8109 9708 8634 2949 7736 6756 9000 9959 1426 4078 1810 2561 9481 2384 7987 6580 64...

result:

ok OK (n = 10000, m = 200000)

Test #24:

score: 0
Accepted
time: 1039ms
memory: 52712kb

input:

10000 200000 8
4341 2303
5786 5734
8189 5597
5013 599
8965 9085
5757 4898
6801 3898
4064 8482
9819 1010
5285 139
6101 3406
6977 1121
7176 1780
4997 5389
616 3334
572 416
2516 4
742 8531
765 9471
3427 9332
8017 5445
1909 8766
4035 2839
5389 8262
9798 9399
4884 2098
3496 1070
3830 3926
9787 5783
4993 ...

output:

7342 7913 8607 7539 4284 8183 3135 4508 5022 3520 4889 7318 9445 4510 9352 7120 7348 4366 3945 872 2295 762 3668 2940 5548 886 79 9554 7158 9682 8457 478 4799 2884 4990 7371 37 1035 7183 4553 5451 4729 8219 6242 1855 4485 1863 4505 3548 991 8184 7681 9811 3325 7929 1768 103 3979 5447 4311 7451 2371 ...

result:

ok OK (n = 10000, m = 200000)

Test #25:

score: 0
Accepted
time: 1002ms
memory: 52528kb

input:

10000 200000 8
3930 5634
5297 1113
2260 9235
6143 5777
9951 8103
5378 8844
4858 4701
1141 1266
9200 1752
2072 3094
6597 3169
5537 5214
5626 6444
7944 5343
237 1641
1505 6890
9613 3567
7027 1782
2566 7572
6830 5122
5618 2380
7375 6441
2493 3794
254 1264
1248 4256
4362 1100
1744 2290
4130 8407
1501 86...

output:

1597 4096 4720 9716 7021 8374 6916 6129 2551 3377 9133 6004 3127 4754 8416 1900 2568 6572 3997 8286 5638 415 3966 6720 1930 5332 7123 4258 1863 2034 8783 7435 3070 1500 6723 9125 5741 9913 5037 2832 9388 4783 4111 7322 8958 3145 3213 9806 9490 5655 5284 7682 3406 7175 293 1484 5717 6724 3737 1443 81...

result:

ok OK (n = 10000, m = 200000)

Test #26:

score: 0
Accepted
time: 1086ms
memory: 52940kb

input:

10000 200000 8
250 3672
9839 5668
7301 2079
8067 6342
9 4975
9607 2066
9155 1811
9941 3432
8551 629
4925 9987
5919 2483
1940 3439
5 8111
4342 3490
3374 7638
4223 2166
2363 6459
9739 743
1402 4217
6997 4834
4819 1666
9929 4646
6536 3713
3806 7080
7079 7011
5063 5627
2022 6762
1269 8085
1309 3380
5929...

output:

4475 5812 3738 1261 2526 8561 8024 5600 9920 5849 3592 9837 6715 5904 4029 8868 4719 1649 5061 1770 4789 2471 1781 5549 1277 3918 6978 4550 9532 9011 1146 7284 7544 9284 8267 4467 1876 6392 2382 4435 6531 1733 2069 9266 6696 4950 3658 1814 1165 6853 6540 1737 6143 5828 2603 5141 400 6138 6216 3132 4...

result:

ok OK (n = 10000, m = 200000)

Test #27:

score: 0
Accepted
time: 1059ms
memory: 52212kb

input:

10000 200000 8
3302 6417
9413 9399
3313 4131
786 2293
9139 9699
8443 4561
9691 5227
464 4981
7873 7640
3846 819
4065 1347
1636 278
581 470
1146 6526
6905 220
2531 1990
5091 8710
1122 57
3891 6774
6722 1119
1982 5076
4842 5563
1517 4655
9328 8119
273 6638
6329 6210
6476 8054
2405 1312
1326 703
8278 3...

output:

3827 3213 8748 1240 5925 5820 7295 5487 9414 8867 8974 7017 2421 2882 3916 5036 7136 3482 2349 1733 2960 194 7810 9261 6931 1727 5561 7409 5624 5397 4670 7400 1134 2710 5737 5893 238 5157 5843 6822 6971 3347 4326 457 4575 6794 7584 7960 5939 1778 5331 4472 406 2558 2781 1496 8934 8129 641 2221 5320 ...

result:

ok OK (n = 10000, m = 200000)

Test #28:

score: 0
Accepted
time: 1064ms
memory: 53160kb

input:

10000 200000 8
3084 3869
4018 2306
296 5389
4299 3629
7339 2276
1885 6331
6469 4950
2711 5913
7166 2786
8833 5589
1036 9761
9475 904
7264 2290
6037 5553
8538 3088
5159 1113
9688 3643
3759 1510
4493 9454
1740 6427
8322 5352
357 5133
2320 9267
9060 6912
9835 147
5047 6007
7724 4978
5151 1971
4181 376
...

output:

4564 7797 8110 7463 8242 7240 6879 2695 6027 6445 4819 5900 125 1480 7214 6903 9090 9043 7096 9687 8185 452 5320 8266 4851 6216 2996 1997 9760 1670 5509 97 2265 3481 9593 7520 3359 8365 8053 5213 8303 2390 7758 8287 5542 2696 9958 6188 982 1306 6000 2507 3715 3760 7837 3518 8247 1937 5818 8265 6467 ...

result:

ok OK (n = 10000, m = 200000)

Test #29:

score: 0
Accepted
time: 1049ms
memory: 51944kb

input:

10000 200000 8
9597 6028
3656 4390
8250 5855
8607 352
4611 2706
9934 7374
9486 979
6681 6227
6429 6067
9887 4297
6831 7725
5456 5316
54 3573
9016 570
8272 6242
2109 9535
6155 1258
7653 5102
3208 2257
2051 757
3836 2495
6474 3355
8945 7549
3001 3458
5766 7537
1216 5016
5767 7532
9508 62
9873 2398
673...

output:

5429 4914 893 5255 5077 2421 9162 2467 6660 6263 2876 53 1290 4042 8086 7299 1136 2519 5906 1847 4511 2790 6676 2628 6929 5578 2261 897 3799 8352 5950 3896 4352 7596 2053 3933 6220 3142 4805 8704 7802 7731 2512 6920 3413 7748 9300 5576 7549 212 3585 8262 4256 3641 7857 7821 9522 9071 8590 7275 351 3...

result:

ok OK (n = 10000, m = 200000)

Test #30:

score: 0
Accepted
time: 1075ms
memory: 51652kb

input:

10000 200000 8
2841 2895
8325 5650
7175 5527
3709 2461
954 989
2590 7692
8743 3316
2375 5924
5663 7482
7008 6944
1452 5240
9580 3515
8952 4318
82 1578
6108 9683
3380 7256
4492 1555
2801 833
37 5183
7656 4109
8526 6505
3193 228
1390 9500
1152 7758
8065 8808
4837 3239
605 5717
5475 5585
8403 6770
2849...

output:

520 6168 7547 7196 2207 8747 8531 4311 3595 7085 2268 3826 8662 9555 3165 6360 5129 8454 2450 8288 3023 9393 9056 3988 4802 983 3496 6661 6715 5531 8346 6907 5586 199 5018 5462 4294 4077 5695 6665 1290 7183 6682 4993 2670 3846 1726 8995 7469 3130 9772 315 5815 3841 6465 2887 5889 9997 6437 5250 4795...

result:

ok OK (n = 10000, m = 200000)

Test #31:

score: 0
Accepted
time: 1102ms
memory: 52188kb

input:

10000 200000 8
2816 4469
8026 6086
7071 4407
9605 9956
6368 7125
9853 7284
4241 1959
9793 5004
4867 7032
196 3530
4897 2305
1847 5501
3957 4526
9236 8577
2046 3410
8972 4276
4699 4534
9206 8703
4979 8232
8553 6484
2391 7381
513 5754
9656 5122
3511 9811
6734 3960
5908 674
2236 9534
3053 8540
9771 349...

output:

7938 9343 4547 9086 6094 883 2323 7334 7425 2703 6334 1156 8203 669 6268 7887 9721 3372 1559 9426 8497 9792 5701 1282 9519 8995 2814 532 9368 1849 9359 4766 9800 237 8626 5462 2383 4254 4646 3760 8927 4450 5923 2113 8672 2141 1474 3386 1619 2601 2848 9788 5551 5195 2110 1137 9898 377 7470 5504 7707 ...

result:

ok OK (n = 10000, m = 200000)

Extra Test:

score: 0
Extra Test Passed