QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#434228#8787. Unusual Caseucup-team987#AC ✓886ms30008kbC++238.6kb2024-06-08 15:12:472024-06-08 15:12:51

Judging History

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

  • [2024-06-08 15:12:51]
  • 评测
  • 测评结果:AC
  • 用时:886ms
  • 内存:30008kb
  • [2024-06-08 15:12:47]
  • 提交

answer

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

namespace {

void solve() {
  Int n, m, k;
  scan(n, m, k);
  Vec<Pair<Int, Int>> edges(m);
  for ([i, j] : edges) {
    scan(i, j);
    --i, --j;
    if (j < i) {
      std::swap(i, j);
    }
  }
  if (n == 5) {
    print("1 3 5 2 4");
    print("5 1 4 3 2");
    return;
  }
  ranges::sort(edges);
  Vec<bool> used(m);
  while (k--) {
    Vec<Pair<signed, signed>> eg;
    for (e : rep(m) | views::filter($(!used[$1]))) {
      auto [i, j] = edges[e];
      eg.emplace_back(i + 1, j + 1);
      eg.emplace_back(j + 1, i + 1);
    }
    auto ans = hamil::work(n, eg);
    assert(len(ans) == n);
    print(ans);
    for (k : rep(n - 1)) {
      Int i = ans[k] - 1;
      Int j = ans[k + 1] - 1;
      if (j < i) {
        std::swap(i, j);
      }
      Int e = ranges::lower_bound(edges, Pair(i, j)) - edges.begin();
      used[e] = true;
    }
  }
}

}  // namespace

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::setprecision(std::numeric_limits<Float>::max_digits10);

  solve();
}

#else  // __INCLUDE_LEVEL__

#include <bits/stdc++.h>

// https://codeforces.com/blog/entry/90513
namespace hamil {
using namespace std;
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) {
  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);
  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) {
    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;
    }
  }
  return vi();
}
}  // namespace hamil

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using i128 = __int128_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using u128 = __uint128_t;

using Int = int64_t;
using Float = double;
using Str = std::string;

template <class T1, class T2>
using Pair = std::pair<T1, T2>;

template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T, size_t N>
using Arr = std::array<T, N>;

template <class T>
using Vec = std::vector<T>;

template <class T>
using Set = std::set<T>;

template <class T>
using Multiset = std::multiset<T>;

template <class K, class T>
using Map = std::map<K, T>;

template <class T>
using MinHeap = std::priority_queue<T, Vec<T>, std::greater<T>>;

template <class T>
using MaxHeap = std::priority_queue<T>;

namespace ranges = std::ranges;
namespace views = std::views;

inline constexpr auto len = ranges::ssize;
inline constexpr auto rev = views::reverse;

constexpr auto rep(Int l, Int r) { return views::iota(std::min(l, r), r); }
constexpr auto rep(Int n) { return rep(0, n); }
constexpr auto rep1(Int l, Int r) { return rep(l, r + 1); }
constexpr auto rep1(Int n) { return rep(1, n + 1); }

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

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

template <std::signed_integral T = Int>
T inf() {
  T ret;
  std::memset(&ret, 0x3f, sizeof(ret));
  return ret;
}

template <std::floating_point T>
T inf() {
  return std::numeric_limits<T>::infinity();
}

template <class T>
concept Range = ranges::range<T> && !std::convertible_to<T, std::string_view>;

template <class T>
concept TupleLike = std::__is_tuple_like<T>::value && !Range<T>;

namespace std {

istream& operator>>(istream& is, Range auto&& r) {
  for (auto&& e : r) {
    is >> e;
  }
  return is;
}

istream& operator>>(istream& is, TupleLike auto&& t) {
  return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}

ostream& operator<<(ostream& os, Range auto&& r) {
  for (string_view sep = ""; auto&& e : r) {
    os << exchange(sep, " ") << e;
  }
  return os;
}

ostream& operator<<(ostream& os, TupleLike auto&& t) {
  const auto f = [&](auto&... xs) -> ostream& {
    [[maybe_unused]] string_view sep = "";
    ((os << exchange(sep, " ") << xs), ...);
    return os;
  };
  return apply(f, t);
}

}  // namespace std

#define DEF_INC_OR_DEC(op) \
  auto& operator op(Range auto&& r) { \
    for (auto&& e : r) { \
      op e; \
    } \
    return r; \
  } \
  auto& operator op(TupleLike auto&& t) { \
    std::apply([](auto&... xs) { (op xs, ...); }, t); \
    return t; \
  }

DEF_INC_OR_DEC(++)
DEF_INC_OR_DEC(--)

#undef DEF_INC_OR_DEC

void scan(auto&&... xs) { std::cin >> std::tie(xs...); }
void print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; }

#define $(...) \
  [&]<class T1 = int, class T2 = int>([[maybe_unused]] T1&& $1 = 0, \
                                      [[maybe_unused]] T2&& $2 = 0) \
      ->decltype(auto) { \
    return __VA_ARGS__; \
  }

template <class F>
class fix {
 public:
  explicit fix(F f) : f_(std::move(f)) {}

  decltype(auto) operator()(auto&&... xs) const {
    return f_(std::ref(*this), std::forward<decltype(xs)>(xs)...);
  }

 private:
  F f_;
};

#define for(...) for ([[maybe_unused]] auto&& __VA_ARGS__)

#endif  // __INCLUDE_LEVEL__

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3636kb

input:

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

output:

1 3 5 2 4
5 1 4 3 2

result:

ok OK (n = 5, m = 9)

Test #2:

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

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:

2041 9300 7628 4940 1370 1911 7482 1686 642 3987 7910 7723 6171 6192 3518 9558 6587 6728 2462 8078 3607 8635 150 4652 6130 9842 2278 8419 3219 2764 272 5672 4033 7266 3148 8089 5653 5968 7965 7303 6617 6768 9109 2153 601 9019 9565 8276 1004 2355 3891 9388 1275 725 8057 8412 5080 2139 1117 2941 6871 ...

result:

ok OK (n = 10000, m = 200000)

Test #3:

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

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:

6267 9132 2650 9427 7611 8243 7828 5486 1377 8691 8850 7752 8180 1410 8577 9155 5857 1024 306 5180 6190 8531 6902 5202 2332 266 269 1952 2069 8777 4267 4991 8767 8832 2718 5764 9863 8851 1539 3618 7308 4824 2415 2411 1940 5569 4010 6932 7394 8713 4688 8175 92 3138 5645 9102 4907 3420 5260 9026 3431 ...

result:

ok OK (n = 10000, m = 200000)

Test #4:

score: 0
Accepted
time: 845ms
memory: 28356kb

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:

9513 4901 7825 7000 3432 8161 8347 1782 4410 5751 4940 8976 113 5591 8286 3151 1784 4071 872 5806 6919 3158 2308 4497 6170 9535 4306 4890 7539 2618 2654 7583 3450 2302 3441 4619 9048 6908 5488 7474 8838 2858 8571 173 9918 6607 1483 3866 2823 980 3874 8159 568 2221 7245 9799 1461 7972 9532 6099 3187 ...

result:

ok OK (n = 10000, m = 200000)

Test #5:

score: 0
Accepted
time: 840ms
memory: 27744kb

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:

2751 4884 2501 511 8260 5280 3230 3777 8527 127 8499 8617 7982 7042 1547 8855 1297 9438 1681 3387 8955 4325 6524 2827 4846 7700 7948 7766 7485 6512 8187 5335 8873 2313 1756 9432 6429 6419 328 1010 2279 4888 2912 8903 5398 8418 145 51 1721 102 6809 1971 4524 4658 7614 718 1502 563 2321 393 7191 8875 ...

result:

ok OK (n = 10000, m = 200000)

Test #6:

score: 0
Accepted
time: 789ms
memory: 28892kb

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:

3086 2042 3032 9953 6342 464 2579 666 3908 1845 4262 8941 1660 2798 8294 4811 2881 9954 8935 9019 2190 4650 1450 5402 6801 285 9487 7280 6954 3476 2478 4398 7898 2251 2860 9 456 2075 6262 4983 3081 2728 6439 903 2934 4934 1595 2575 6290 2376 3497 7805 10 2123 5885 5278 1893 5481 1476 7022 7806 6453 ...

result:

ok OK (n = 10000, m = 200000)

Test #7:

score: 0
Accepted
time: 815ms
memory: 29536kb

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:

7551 7844 883 6152 8408 9904 7379 2061 6329 1763 903 832 4325 3128 1302 597 283 2432 152 2108 3611 3715 674 1530 2291 9125 7703 1921 685 5229 4961 8130 849 1364 6689 8578 8714 9898 4320 9574 6016 7614 1633 6574 9443 2997 8283 2900 8128 1660 82 195 1239 7402 8379 2928 1496 1786 3918 6326 1473 5410 90...

result:

ok OK (n = 10000, m = 200000)

Test #8:

score: 0
Accepted
time: 871ms
memory: 27584kb

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:

645 435 134 2559 3782 3981 4025 2625 3941 1653 3608 114 4433 2770 5015 5118 6394 2007 4824 2640 1820 8298 9332 3079 1558 5739 7864 6415 4861 5512 4182 4673 2023 9994 3087 6597 6044 3393 9014 6920 8865 6899 8283 5039 9036 5069 2924 6112 1055 3392 5463 6193 5753 6521 8988 4746 8794 6005 6443 3507 83 7...

result:

ok OK (n = 10000, m = 200000)

Test #9:

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

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:

143 6728 4577 109 9742 9002 304 7909 2029 1704 4612 2212 5442 7793 953 4753 5829 5028 3915 7706 3511 8058 77 4998 4725 7660 8560 7145 7011 6647 7119 4951 6201 5041 4442 9739 5749 4102 8737 4234 1504 7454 5315 8402 8746 2168 6566 2615 2916 1571 8189 6547 1568 1566 8312 8183 766 3944 9465 8666 3272 34...

result:

ok OK (n = 10000, m = 200000)

Test #10:

score: 0
Accepted
time: 845ms
memory: 27012kb

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:

4214 1722 486 542 286 631 3303 8045 995 2663 4288 1924 5647 3341 9217 4880 206 7355 1572 1131 8605 8156 1239 9974 4310 5794 800 6579 2016 3413 4515 6694 4947 4566 8695 6692 3984 5152 7814 2327 8125 635 1429 9721 1022 6657 8282 7705 2446 3802 1315 4840 6979 7192 6723 3322 5558 3779 4662 3136 9715 952...

result:

ok OK (n = 10000, m = 200000)

Test #11:

score: 0
Accepted
time: 836ms
memory: 27676kb

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:

1373 17 5133 1058 9251 2047 9565 9169 8433 3401 2701 3958 3548 6187 6615 8945 8169 5786 1544 9350 2082 2312 6339 7962 7607 6433 231 1899 2149 2705 8508 6239 2435 9052 3968 6590 7287 8565 9860 9198 294 1120 1552 6279 6408 2353 2340 8853 4270 3898 774 5544 5988 1268 2576 1039 3849 6372 5434 2205 3161 ...

result:

ok OK (n = 10000, m = 200000)

Test #12:

score: 0
Accepted
time: 883ms
memory: 27556kb

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:

1254 8665 3092 3413 8580 2056 2063 9874 7573 9369 8838 5766 9600 2111 7923 2788 2692 8502 6111 5438 8907 7392 6563 9783 5697 7077 3429 2034 3872 8177 3815 8590 8279 8608 7778 2280 6760 1395 9485 2558 3353 7815 3025 8224 6516 8753 7792 5661 5950 6315 1037 8870 4368 8215 3505 8744 5776 5259 2708 2914 ...

result:

ok OK (n = 10000, m = 200000)

Test #13:

score: 0
Accepted
time: 824ms
memory: 28444kb

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:

4815 4412 8936 1037 5978 4710 8594 6322 9670 7835 6127 1956 1130 6921 2983 6252 3555 6956 5558 6302 1733 2904 9449 6211 9531 3989 6884 2411 7707 9370 4430 1773 7979 9145 5041 9695 7794 5100 4723 96 7184 2985 2529 7099 6286 8227 9149 592 7466 8906 1393 5438 340 5039 7013 2165 4508 3020 2847 1672 2380...

result:

ok OK (n = 10000, m = 200000)

Test #14:

score: 0
Accepted
time: 842ms
memory: 27660kb

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:

5301 8224 6654 2219 7385 7153 2932 4832 2256 92 8421 5793 8154 3603 5157 6040 36 662 9106 5894 4893 2884 1353 8055 9692 464 8272 7930 170 4727 236 4923 9285 8937 8892 8696 3990 5127 6123 7446 7017 1562 6163 4235 12 1228 4488 3094 2602 4695 6093 8816 8436 432 4384 1921 2835 9774 4031 2317 3552 9982 8...

result:

ok OK (n = 10000, m = 200000)

Test #15:

score: 0
Accepted
time: 822ms
memory: 28720kb

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:

8990 9375 9744 5885 3482 2151 8377 8026 9634 5605 6682 8973 3160 4720 4777 8600 8006 5923 7371 5985 9496 3179 4891 2786 7667 6453 3657 4021 8709 7029 3144 1520 1276 5199 1417 6473 4130 4689 5509 4512 7410 7828 1535 6520 3966 1478 6689 3995 2157 127 7204 6600 2702 985 7669 2894 4459 3280 2623 1029 32...

result:

ok OK (n = 10000, m = 200000)

Test #16:

score: 0
Accepted
time: 779ms
memory: 28512kb

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:

3833 4839 8478 6650 8846 2853 8500 6406 6114 9052 2161 5088 5796 5535 1935 9211 4915 1066 9895 6168 6481 8390 7190 6844 1319 7335 4381 5488 3893 5462 1265 4532 4439 2419 8309 5164 65 8587 719 8570 5218 9575 6946 2485 7666 8982 788 6649 2785 7583 6340 2992 3925 2496 8661 9338 2177 560 1798 6378 8202 ...

result:

ok OK (n = 10000, m = 200000)

Test #17:

score: 0
Accepted
time: 825ms
memory: 29184kb

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:

7995 8803 1477 1787 9383 5319 1962 7838 1504 3075 5655 5080 4591 5493 7976 8027 1483 5132 1741 4204 8 393 9532 9157 5110 1036 5366 135 6539 726 4924 739 6943 7564 8904 2910 9397 6712 1441 3235 5140 3367 3206 8332 5582 3529 8129 8122 3308 8713 2915 8949 8195 3542 447 3666 8518 4626 2327 6970 9457 959...

result:

ok OK (n = 10000, m = 200000)

Test #18:

score: 0
Accepted
time: 842ms
memory: 28272kb

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:

5431 2116 4337 9098 2081 6793 5511 4585 2722 7706 2068 5879 313 6742 8256 2566 2838 4185 1146 4808 1893 3970 5031 7644 7120 2691 7356 4889 3811 942 1835 5137 2568 4866 3684 2005 6850 9762 4002 7816 8079 4798 6193 3694 3607 5839 356 8095 5939 5296 6295 2966 4254 7384 5479 6552 4553 6760 7689 679 8984...

result:

ok OK (n = 10000, m = 200000)

Test #19:

score: 0
Accepted
time: 836ms
memory: 29196kb

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:

5784 9746 2983 4931 6183 3466 7917 7968 9793 4705 6290 2832 4439 827 3614 4646 9819 2763 2197 8190 2309 2005 1794 9195 7227 2103 2664 3455 6121 2761 311 4617 7495 362 3553 2733 6081 8488 5963 1721 7321 9550 8028 6166 7000 7935 6917 5637 4655 9140 4080 98 2460 8667 899 8277 3584 278 3118 6885 7342 75...

result:

ok OK (n = 10000, m = 200000)

Test #20:

score: 0
Accepted
time: 878ms
memory: 28156kb

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:

7398 2535 9936 9319 8462 1581 9549 7609 1941 5524 4133 4818 3796 9958 5057 2415 2894 3487 7291 6795 2517 9106 3549 8414 9683 91 8188 6648 4164 7984 5008 8711 9057 7547 4617 2543 5943 4529 5300 6254 7210 7884 6994 3792 6684 2859 5036 5905 3511 7626 3678 431 4124 5754 5949 7699 2291 2898 595 9763 8949...

result:

ok OK (n = 10000, m = 200000)

Test #21:

score: 0
Accepted
time: 803ms
memory: 28668kb

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:

5768 5414 9287 167 4295 5537 5723 6257 982 7270 2008 7665 1431 3002 8343 9841 3992 1443 6597 9543 1222 606 2218 5951 6625 9255 5063 212 4758 4872 8945 2461 8624 5083 4748 7042 7056 8105 4353 3113 5045 4638 911 3784 5233 3339 1551 2953 4776 2834 7532 2061 1974 5600 4184 2749 5679 6459 2911 837 2101 2...

result:

ok OK (n = 10000, m = 200000)

Test #22:

score: 0
Accepted
time: 832ms
memory: 29316kb

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:

8655 5585 5216 9112 7522 3224 5753 7949 9556 3937 2170 2314 8907 1134 9244 2955 2311 69 4567 8704 4464 3476 9428 4401 309 4952 564 6502 1358 5116 6523 7995 6268 9242 273 894 3520 3093 4852 1505 6004 2347 7750 8306 5259 2502 7799 5295 7610 5090 4195 3775 4550 2325 7441 6826 4696 3994 3416 6185 9342 2...

result:

ok OK (n = 10000, m = 200000)

Test #23:

score: 0
Accepted
time: 852ms
memory: 29924kb

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:

7635 8161 7552 9429 2535 2644 1446 9979 142 7405 4454 2101 795 7583 6290 2596 1319 1921 7581 9822 1097 4215 3507 5926 1314 6191 5849 2665 3855 1789 4783 5369 2007 1500 3963 6143 8045 4509 8803 4885 3156 1124 6920 7776 9560 8502 4650 2729 8687 9772 8 307 6968 7343 6455 4501 6420 5171 6495 9036 2236 3...

result:

ok OK (n = 10000, m = 200000)

Test #24:

score: 0
Accepted
time: 878ms
memory: 28748kb

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:

5869 3131 6066 8989 1003 1387 5758 7137 224 3265 3163 4861 216 2763 6550 4927 2401 923 2678 8691 9951 5713 9233 932 7070 3241 5637 9054 4871 1256 3610 3196 7740 6952 6994 6360 1053 330 3678 7038 6622 2331 8920 3167 2098 4176 6685 4928 4510 3075 7075 3385 1001 8047 8761 3059 8486 8693 7733 8803 8332 ...

result:

ok OK (n = 10000, m = 200000)

Test #25:

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

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:

749 773 6452 7647 1365 5428 8733 4524 7165 2256 7117 7764 9399 8069 2263 4384 2130 742 9584 3959 2567 6164 5170 1045 9311 3367 7360 7140 3272 4501 4205 7249 5192 8334 9505 3838 1867 3489 5248 8920 3170 2152 6303 4952 761 5196 7729 765 7484 1514 6281 3347 1587 8707 6664 2906 6558 2845 8627 5097 9470 ...

result:

ok OK (n = 10000, m = 200000)

Test #26:

score: 0
Accepted
time: 853ms
memory: 27908kb

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:

4164 7163 2945 4309 1639 2550 919 5379 1725 2875 5226 1158 6872 898 2994 4811 2048 8880 1778 4543 6918 8070 8168 3051 7854 4557 8091 5206 9610 8935 5869 1434 5043 8696 6884 4899 9250 6478 2882 8418 1986 8493 9909 7051 9433 2527 4945 1237 461 7715 7761 8177 5160 1793 5334 1305 4183 4627 8301 805 2392...

result:

ok OK (n = 10000, m = 200000)

Test #27:

score: 0
Accepted
time: 832ms
memory: 27820kb

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:

24 1655 4052 5570 3388 5393 1910 5953 8345 1816 3848 8890 6558 4246 5219 1964 122 4333 3448 1489 8440 7068 9311 9834 8823 9040 9710 2973 4136 2625 4479 4943 5635 5135 2652 9265 8041 3594 8609 8061 9218 4803 6873 7199 2571 7174 651 2020 3806 6404 5012 2041 7342 422 9970 1565 4852 7678 5306 6501 7750 ...

result:

ok OK (n = 10000, m = 200000)

Test #28:

score: 0
Accepted
time: 769ms
memory: 28196kb

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:

1669 4672 1930 5220 6515 9145 3287 815 558 5635 2766 8459 7419 5574 2443 36 602 8287 6293 7508 6902 2710 5282 5108 7306 5110 5778 6919 4999 7326 2829 3092 9768 4752 8169 5966 1532 3577 8029 5863 5284 1785 7645 7158 14 5341 4839 4860 1882 309 6707 9330 1728 6657 9121 6760 5656 9163 3937 5552 1662 805...

result:

ok OK (n = 10000, m = 200000)

Test #29:

score: 0
Accepted
time: 811ms
memory: 27476kb

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:

5436 2353 2180 2320 3471 2561 5991 4818 4617 400 1179 8817 3395 8932 1182 4056 1942 7485 8234 7684 7953 5137 2569 8566 6604 6661 6360 5375 4334 2562 3453 996 9742 3610 6704 7614 5314 6951 4282 4428 1006 4154 4087 8696 5710 1437 3330 6262 9552 2322 9053 6217 491 7132 6093 9711 2144 9437 2595 7102 930...

result:

ok OK (n = 10000, m = 200000)

Test #30:

score: 0
Accepted
time: 813ms
memory: 27652kb

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:

9507 4573 5619 3142 9829 585 6414 8135 1523 2307 1815 2376 4487 9585 1502 8870 4852 8708 7210 1015 8832 849 9607 8792 3874 1106 9878 826 5320 9040 8419 9985 7328 7978 8199 5051 5900 7011 1221 8139 958 4353 9346 855 2158 2994 4833 2381 6858 9775 323 7244 2514 2166 5554 3166 935 5770 5727 2518 5355 87...

result:

ok OK (n = 10000, m = 200000)

Test #31:

score: 0
Accepted
time: 886ms
memory: 27496kb

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:

9872 2707 4768 3143 7947 7467 6212 7462 8648 6562 1945 8908 811 8925 3859 8160 6875 2156 4104 5529 7378 3313 4962 2840 3902 7770 6098 2888 5295 3941 3744 1405 9916 4705 5577 9640 2852 3548 7458 4665 2817 774 7679 6940 2451 6549 6401 321 5654 4169 8915 8212 7237 209 5273 1383 4176 1857 3310 1080 364 ...

result:

ok OK (n = 10000, m = 200000)

Extra Test:

score: 0
Extra Test Passed