QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#432734#8787. Unusual Caseucup-team087#AC ✓864ms48024kbC++148.4kb2024-06-07 16:14:582024-06-07 16:14:58

Judging History

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

  • [2024-06-07 16:14:58]
  • 评测
  • 测评结果:AC
  • 用时:864ms
  • 内存:48024kb
  • [2024-06-07 16:14:58]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// https://codeforces.com/blog/entry/90743
#include <bits/stdc++.h>
using namespace std;
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;
                }
            }
        }
    }
    vector<vi> used;
    unordered_set<int> caneg;
    void cut(int a, int b) {
    	LCT::cut(a, b);
    	for (int s = 0; s < 2; s++) {
	    	for (int i = 0; i < used[a].size(); i++)
	    		if (used[a][i] == b) {
	    			used[a].erase(used[a].begin() + i);
	    			break;
				}
			if (used[a].size() == 1) caneg.insert(a);
			swap(a, b);
		}
	}
	void link(int a, int b) {
		LCT::link(a, b);
		for (int s = 0; s < 2; s++) {
			used[a].pb(b);
			if (used[a].size() == 2) caneg.erase(a);
			swap(a, b);
		}
	}
    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. 
        
        LCT::init(n);
        if (mx_ch == -1) mx_ch = 1ll * (n + 100) * (n + 50); //default
        used.resize(n + 1);
        caneg.clear();
        for (int i = 1; i <= n; i++) used[i].clear();
        
        vector<vi> edges(n + 1);
        for (auto v : eg)
            edges[v.fi].pb(v.se), 
            edges[v.se].pb(v.fi);
            
        for (int i = 1; i <= n; i++)
            caneg.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 : caneg)
                for (auto s : edges[v])
                    eg.pb(mp(v, s));
			
            shuffle(eg.begin(), eg.end(), x);
            if (eg.size() == 0) break;
            for (auto v : eg) {
                mx_ch--;
                int a = v.fi, b = v.se;
                if (used[a].size() < used[b].size()) swap(a, b);
                if (used[b].size() >= 2) continue;
                if (x() & 1) continue;
                if (LCT::fdr(a) == LCT::fdr(b)) continue;
                if (used[a].size() < 2 && used[b].size() < 2)
                	tot++;
                if (used[a].size() == 2) {
                	int p = used[a][x() % 2];
                	cut(a, p);
                }
                link(a, b);
            }
            if (tot == n - 1) {
                vi cur;
                for (int i = 1; i <= n; i++) 
                    if (used[i].size() <= 1) {
                        int pl = i, ls = 0;
                        while (pl) {
                            cur.pb(pl);
                            int flag = 0;
                            for (auto v : used[pl]) 
                            	if (v != ls) {
                            		ls = pl;
                            		pl = v;
                            		flag = 1;
                            		break;
								}
							if (!flag) break;
                        }
                        break;
                    } 
                return cur;
            }
        }
        //failed to find a path
        return vi();
    }
}


int N, M, K;
vector<pair<int, int>> E;

int main() {
  for (; ~scanf("%d%d%d", &N, &M, &K); ) {
    E.resize(M);
    for (int i = 0; i < M; ++i) {
      scanf("%d%d", &E[i].first, &E[i].second);
    }
    
    map<pair<int, int>, int> ids;
    for (int i = 0; i < M; ++i) {
      ids[E[i]] = i;
      ids[make_pair(E[i].second, E[i].first)] = i;
    }
    
   loop:
    vector<int> on(M, 1);
    vector<vector<int>> ans(K);
    for (int k = 0; k < K; ++k) {
      vector<pair<int, int>> es;
      for (int i = 0; i < M; ++i) if (on[i]) es.push_back(E[i]);
      const auto us = hamil::work(N, es);
// cerr<<"on = "<<on<<", us = "<<us<<endl;
      if (us.empty()) goto loop;
      for (int j = 0; j < N - 1; ++j) {
        const int i = ids[make_pair(us[j], us[j + 1])];
        assert(on[i]);
        on[i] = 0;
      }
      ans[k] = us;
    }
    for (int k = 0; k < K; ++k) {
      for (int j = 0; j < N; ++j) {
        if (j) printf(" ");
        printf("%d", ans[k][j]);
      }
      puts("");
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

3 1 5 2 4
1 4 5 3 2

result:

ok OK (n = 5, m = 9)

Test #2:

score: 0
Accepted
time: 770ms
memory: 46620kb

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:

1548 1169 476 3383 8004 3289 1885 7060 9627 7401 4662 418 7456 3196 5923 4698 5226 8727 1749 8380 8839 6513 3586 1929 1159 4669 1586 3059 240 5877 5248 4711 2948 9224 5668 3850 5902 7537 22 494 4159 2735 4702 7324 8959 6687 794 5263 1206 7470 883 9470 3621 7468 4132 4473 3471 954 4068 4580 2263 2221...

result:

ok OK (n = 10000, m = 200000)

Test #3:

score: 0
Accepted
time: 781ms
memory: 47252kb

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:

4720 7562 8917 9078 4598 5284 6357 4585 724 6388 3873 9855 8290 2474 4813 9042 1199 758 7546 9722 9526 6229 9426 5871 6248 9430 2044 2592 4675 19 438 4722 6442 5440 7913 9821 7879 8843 1060 8216 242 2627 7237 3508 8364 235 3417 9168 8458 2426 5220 8011 6728 6579 2468 9015 2972 8678 5507 6277 6804 79...

result:

ok OK (n = 10000, m = 200000)

Test #4:

score: 0
Accepted
time: 780ms
memory: 47320kb

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:

2398 7954 3780 5769 8994 1641 4733 1713 8622 1821 7779 4359 9920 5330 7762 3155 828 9212 6419 3432 8580 2673 4780 4854 9252 4004 6811 8330 2542 8162 7376 7971 7178 3488 4765 8480 726 7425 1145 9253 339 4059 8408 1300 5831 546 6255 300 7482 2046 1148 3418 6704 9930 1682 5823 8167 5015 7861 2925 9778 ...

result:

ok OK (n = 10000, m = 200000)

Test #5:

score: 0
Accepted
time: 778ms
memory: 46956kb

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:

1743 7542 1863 6732 2087 7511 5836 133 2095 5128 2118 4659 2094 1193 1398 61 8865 8064 1442 2857 9005 7844 2611 8449 266 108 5608 4390 789 7068 2585 204 7198 9495 2927 1644 5802 2334 5687 283 8431 6914 524 6910 2022 5191 5085 1464 9997 5097 5939 9791 9501 4313 1995 3750 2213 1484 4538 5243 9547 9983...

result:

ok OK (n = 10000, m = 200000)

Test #6:

score: 0
Accepted
time: 790ms
memory: 46896kb

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:

2697 4901 6897 6797 1934 2711 7260 202 1234 2823 6898 5154 9408 670 7568 2418 6689 9694 1609 9641 7233 4412 5057 2398 714 9152 2187 6550 806 3159 8291 9638 9749 332 3328 7203 6659 1419 781 9382 4235 573 721 9543 9360 2432 5590 1218 926 8489 3329 4742 1191 276 1975 944 2813 9877 255 8778 6324 9996 30...

result:

ok OK (n = 10000, m = 200000)

Test #7:

score: 0
Accepted
time: 802ms
memory: 46324kb

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:

2007 341 8160 2427 7168 9205 4838 6482 1277 536 1281 4132 5709 6342 9890 5272 7589 2169 3089 4991 2847 5020 940 1623 7662 7221 343 7886 5513 7338 1936 8205 1643 592 3600 5345 3160 9520 7934 2406 8626 809 6781 4666 3611 4954 1879 9789 3806 5112 2338 3604 3515 9096 1744 7562 8755 9705 194 1134 4019 22...

result:

ok OK (n = 10000, m = 200000)

Test #8:

score: 0
Accepted
time: 794ms
memory: 46768kb

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:

4408 7570 8187 5654 3454 1802 270 1087 9051 7592 7157 90 3614 4826 7407 4665 2651 8310 9998 679 9809 3356 9612 3790 5078 715 4010 4553 2173 443 1113 3155 2774 250 2043 4768 593 4316 3705 1231 7631 343 3883 2886 7269 7498 5961 3958 431 1221 4267 1403 4671 9423 7585 9815 5759 9434 9595 4093 3018 4819 ...

result:

ok OK (n = 10000, m = 200000)

Test #9:

score: 0
Accepted
time: 814ms
memory: 46472kb

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:

532 434 4933 8460 7964 1341 5951 3700 8952 9333 3145 6729 3337 9113 3579 8002 5098 5286 1975 2922 787 590 200 8746 8779 8401 7010 3956 6610 2112 7201 9145 4773 1241 1544 1596 1211 1376 7812 4310 2186 6767 9250 3810 1847 2581 8722 6932 6548 63 2896 113 8895 37 2603 2031 9172 6876 7130 4588 2353 2043 ...

result:

ok OK (n = 10000, m = 200000)

Test #10:

score: 0
Accepted
time: 814ms
memory: 48024kb

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:

2260 8796 1968 297 8556 7275 9500 3182 7423 5274 5055 4845 8917 7959 8983 4366 386 2880 9009 7399 4961 1304 3775 2378 8208 2605 9188 1362 1152 4748 6313 7713 2173 4231 9437 7584 1326 2801 9542 1466 6613 6141 6439 8551 4545 8664 9525 2347 8498 1450 3319 4885 9718 6737 7176 9816 1982 9968 8673 230 602...

result:

ok OK (n = 10000, m = 200000)

Test #11:

score: 0
Accepted
time: 766ms
memory: 47360kb

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:

300 6796 3747 8940 9228 3369 7916 7614 6006 9243 2878 3878 4185 7305 7443 8253 4187 2798 7862 3672 9485 6590 8778 6596 5327 5551 200 7116 6417 4436 2379 1995 2678 5340 2253 7751 4438 2797 9981 8801 6981 3244 837 1233 6564 587 5993 6432 6207 8829 9834 9512 1199 3960 2588 2136 8754 7923 5352 7440 8444...

result:

ok OK (n = 10000, m = 200000)

Test #12:

score: 0
Accepted
time: 775ms
memory: 46612kb

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:

6678 5257 606 7388 7524 5042 584 9741 4675 6555 4290 2174 7595 9279 9889 1811 9388 4049 7335 3439 8344 7641 986 1180 9842 2456 1620 5023 2061 7149 8233 953 6554 9228 4470 5750 6141 8389 4295 5782 4976 5187 4896 619 9184 8456 604 286 9248 1176 1792 886 7132 6760 5198 3226 7469 4699 1493 5859 9210 381...

result:

ok OK (n = 10000, m = 200000)

Test #13:

score: 0
Accepted
time: 738ms
memory: 46876kb

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:

160 7342 7740 7565 2357 8286 7552 8344 4608 3667 4127 8262 2733 1314 3486 945 7578 9013 318 2412 3264 3082 7147 4133 3041 6206 1501 3799 1394 5967 7778 3978 8712 6669 4709 2780 2823 9690 4500 5803 8299 2660 5090 9416 9541 9645 3470 3374 1580 9340 546 2965 3272 9302 8118 4221 5280 3857 4515 7678 154 ...

result:

ok OK (n = 10000, m = 200000)

Test #14:

score: 0
Accepted
time: 781ms
memory: 46648kb

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:

1747 1494 9638 258 7117 1045 2389 9062 3656 1975 3670 8619 2322 3835 7424 4059 7130 1424 9258 5069 9371 6350 5183 1977 2660 426 4256 7453 6212 5825 6829 6260 8019 1144 9955 685 7911 3761 9683 9537 234 2688 2984 6752 1171 3920 8427 4322 9637 2691 9812 1752 9204 7526 3632 1184 1669 4514 4298 4807 8607...

result:

ok OK (n = 10000, m = 200000)

Test #15:

score: 0
Accepted
time: 772ms
memory: 46116kb

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:

3943 9132 3927 8262 5499 471 8076 5830 8033 935 863 9498 9067 90 9824 3350 8510 345 5998 2375 1972 7266 1712 9003 1275 5602 7962 851 4692 8921 4367 1745 5569 2714 2521 9285 3663 9321 4032 6145 3750 9661 9788 8909 2486 3520 2087 4067 1714 1616 7044 1542 2574 8247 9502 6228 405 4745 8916 4353 2715 347...

result:

ok OK (n = 10000, m = 200000)

Test #16:

score: 0
Accepted
time: 793ms
memory: 46740kb

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:

523 4296 9620 4662 9463 9407 3144 2131 1028 7243 5143 7331 2565 7582 2086 3345 936 7756 6858 8949 6372 7025 4522 1423 325 3789 4654 5100 447 372 5584 8278 2940 9945 6232 7710 558 8494 4469 8328 5561 3464 9813 9183 3091 3558 9750 1196 3839 7527 1637 1983 2126 664 2213 4276 5749 1541 6492 7605 7503 30...

result:

ok OK (n = 10000, m = 200000)

Test #17:

score: 0
Accepted
time: 770ms
memory: 46844kb

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:

2859 8946 4842 8986 9083 8392 7819 4886 4794 30 681 2895 1820 3540 8859 3701 2776 2964 7669 585 66 8684 3749 3755 3482 4401 1401 7650 8478 1005 3344 7524 1910 7331 2426 5287 2321 6159 9156 9685 2348 8163 9519 1727 8442 3623 7995 5196 9202 4158 2619 5016 7123 2290 5793 3437 150 7648 4699 7805 3558 32...

result:

ok OK (n = 10000, m = 200000)

Test #18:

score: 0
Accepted
time: 768ms
memory: 47088kb

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:

1284 8221 5669 5046 9628 4103 137 999 248 6356 3316 9083 8374 2452 2148 2662 6078 4394 8529 548 5230 1622 8418 1224 8632 3393 4185 7946 4606 3782 6845 4058 7582 6965 1606 879 7007 1710 1049 6298 2243 2961 8116 7345 6957 6479 8651 326 9375 5450 2656 9720 1013 3562 7862 3414 7888 2157 2881 2173 3787 4...

result:

ok OK (n = 10000, m = 200000)

Test #19:

score: 0
Accepted
time: 758ms
memory: 47148kb

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:

2761 5581 652 9288 1749 8107 8461 4483 1437 6213 4671 5801 5340 98 9302 9053 7309 1157 9819 5354 1596 8239 6624 5910 8295 6430 1170 6833 8283 7719 7977 5749 3819 2691 6740 2131 1430 2675 2170 2219 6909 149 6914 3025 2348 3370 9711 245 3507 2478 4156 2665 5819 9344 6141 4556 4746 3803 4987 9287 2603 ...

result:

ok OK (n = 10000, m = 200000)

Test #20:

score: 0
Accepted
time: 786ms
memory: 47256kb

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:

2011 1465 5234 1953 2654 4828 811 7484 1841 4762 173 6182 6782 6586 9387 5213 7521 3334 594 4147 3175 7421 8451 4395 8360 879 629 7063 4539 3759 7259 8669 3964 5471 2226 9689 7686 2893 3035 6493 8121 1310 6926 6452 5419 6409 6757 7993 5654 8946 2534 7882 2768 9824 3904 2252 8085 2643 2733 6743 7404 ...

result:

ok OK (n = 10000, m = 200000)

Test #21:

score: 0
Accepted
time: 781ms
memory: 46464kb

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:

5894 9618 1194 6863 4125 3840 9761 4253 5634 1822 6799 2219 9193 4877 3716 2049 2479 8429 1857 5692 3807 2139 538 9384 9331 5386 6971 566 2194 5738 4974 171 7105 7845 9773 1077 6579 4742 5144 5441 1891 3393 5306 515 4351 7660 7352 7296 7775 6923 6050 6595 6453 4155 4716 5983 3475 1688 1347 9604 7156...

result:

ok OK (n = 10000, m = 200000)

Test #22:

score: 0
Accepted
time: 773ms
memory: 45664kb

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:

5895 9730 9829 4627 8764 8377 2731 9741 5857 6375 2120 8431 4990 5582 816 1418 2746 8050 7646 4796 7815 7787 3609 5220 6751 4302 646 9967 8411 8271 5940 346 247 3912 856 4709 2135 9320 8019 5937 6977 94 5638 16 868 5918 1522 1590 3438 3900 1656 68 9717 1981 2230 6030 5823 7772 7973 2436 9789 8415 87...

result:

ok OK (n = 10000, m = 200000)

Test #23:

score: 0
Accepted
time: 794ms
memory: 47244kb

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:

3614 991 8562 9613 3371 9192 5266 8149 7108 6338 1937 9155 4448 8462 7419 4287 8531 8256 9038 5322 4542 2944 5740 9428 1247 6766 6160 9780 494 7939 6478 1858 2495 4282 9846 684 6841 4308 9238 5298 5973 1758 9414 5505 4395 3490 5804 1082 8366 413 5426 5216 481 1637 4549 1418 4466 5644 7433 9598 9261 ...

result:

ok OK (n = 10000, m = 200000)

Test #24:

score: 0
Accepted
time: 816ms
memory: 46940kb

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:

1560 5876 6056 3422 1743 514 294 8703 9634 7528 2365 5038 5070 808 8222 1155 1292 9824 2099 3677 4820 9858 5337 7596 2875 7432 7575 7144 1206 4144 8364 6831 8622 2966 3508 9809 4132 1140 9244 8919 5464 7687 8844 8343 8076 272 1442 5799 1253 4358 8567 2968 2978 6618 978 5887 67 1952 4736 8860 5180 87...

result:

ok OK (n = 10000, m = 200000)

Test #25:

score: 0
Accepted
time: 787ms
memory: 47028kb

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:

3856 1533 5846 779 2180 5895 9404 6443 151 8511 7621 3 2702 7944 3278 4702 4030 8227 2495 2585 3073 4891 5286 219 1739 5585 4198 9428 4543 2386 9087 6802 7499 8284 1325 1414 1235 852 8912 1883 7407 5241 7788 9273 9190 2590 6247 3949 7546 7480 7001 2550 9142 5447 2316 21 7494 9837 7834 2749 8896 4570...

result:

ok OK (n = 10000, m = 200000)

Test #26:

score: 0
Accepted
time: 796ms
memory: 45864kb

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:

6912 2234 8615 9822 6359 1744 7217 2116 2146 5068 3361 4957 3764 7290 6362 9185 1162 1395 7857 4208 8574 9456 5316 6449 594 1752 1338 3235 3761 9142 2150 8539 5792 1955 5590 2128 3063 2049 6514 4947 8030 7664 9365 4082 2259 3188 173 9559 809 7364 6998 2002 8359 9609 2515 4185 5143 751 476 7128 4373 ...

result:

ok OK (n = 10000, m = 200000)

Test #27:

score: 0
Accepted
time: 809ms
memory: 47200kb

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:

6778 4550 8929 1364 6487 559 886 8052 1508 5350 2092 7954 2805 3594 1521 4596 7309 9256 7429 6384 5986 6016 8453 4933 8409 5020 3148 2197 6291 164 9679 7484 8920 4252 8988 2740 5573 979 7482 8491 5260 6501 7652 1907 9175 6127 2911 1017 2255 1629 1655 4292 4153 9089 8971 5623 6909 9292 7992 7307 5991...

result:

ok OK (n = 10000, m = 200000)

Test #28:

score: 0
Accepted
time: 819ms
memory: 46340kb

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:

8845 8605 6004 8520 4886 3511 4692 8988 666 9875 3607 4553 7237 1738 2766 8459 39 8305 1978 4031 8962 1034 9295 882 991 8804 2842 3029 8124 6627 9988 8943 9423 5825 102 7837 2520 5327 5892 8173 3387 1239 1735 8113 2257 1599 9386 1564 97 7306 119 470 5645 7534 1993 9850 7715 868 1915 860 4095 3286 63...

result:

ok OK (n = 10000, m = 200000)

Test #29:

score: 0
Accepted
time: 864ms
memory: 46284kb

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:

923 52 5715 9301 6272 580 7399 4092 7630 6537 8864 5595 8069 8482 5180 339 2610 3143 2334 3908 1307 6077 8198 7574 5791 5230 9594 215 9587 4375 9143 9943 9088 872 663 455 408 5775 6063 7977 4298 363 9421 8057 9722 6239 4481 5328 4635 454 2445 5567 7366 5795 4822 9256 9729 2773 5620 9102 3771 4667 52...

result:

ok OK (n = 10000, m = 200000)

Test #30:

score: 0
Accepted
time: 830ms
memory: 46864kb

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:

2486 2715 5811 7523 4303 8101 7544 879 9954 5758 95 519 7547 207 3904 4196 8274 2424 2447 4749 2359 9126 5552 237 5154 760 1207 3796 2008 7471 9696 3712 961 5544 3829 5809 3006 2372 1848 5108 6 8863 1875 8596 576 1454 7720 8088 5527 987 7939 2740 6436 1254 9483 7970 5630 3238 5421 1058 9284 5237 112...

result:

ok OK (n = 10000, m = 200000)

Test #31:

score: 0
Accepted
time: 752ms
memory: 47096kb

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:

148 888 6642 9914 7325 370 76 7041 9122 7033 8749 2822 5635 4780 8521 4897 7018 2512 2086 1260 5232 8485 3694 8352 5193 5703 863 7404 6217 6697 279 3554 8773 7941 7524 8289 2598 5198 819 8874 9819 4292 1003 4747 4619 6744 7312 724 3375 6208 8998 6044 1602 2244 8177 3084 7611 9621 3230 4621 7316 7156...

result:

ok OK (n = 10000, m = 200000)

Extra Test:

score: 0
Extra Test Passed