QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#105554#6413. Classical Graph Theory ProblemmaspyAC ✓619ms81216kbC++2320.5kb2023-05-14 12:51:512023-05-14 12:51:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-14 12:51:55]
  • 评测
  • 测评结果:AC
  • 用时:619ms
  • 内存:81216kb
  • [2023-05-14 12:51:51]
  • 提交

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sum = 0;
  for (auto &&a: A) sum += a;
  return sum;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  assert(!que.empty());
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  assert(!que.empty());
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.write(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};

struct has_read_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.read(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <typename T,
            typename enable_if<has_read<T>::value>::type * = nullptr>
  inline bool read_single(T &x) {
    x.read();
    return true;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <size_t N = 0, typename T>
  void read_single_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
      auto &x = std::get<N>(t);
      read_single(x);
      read_single_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool read_single(tuple<T...> &tpl) {
    read_single_tuple(tpl);
    return true;
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <typename T,
            typename enable_if<has_write<T>::value>::type * = nullptr>
  inline void write(T x) {
    x.write();
  }
  template <class T>
  void write(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <size_t N = 0, typename T>
  void write_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
      if constexpr (N > 0) { write(' '); }
      const auto x = std::get<N>(t);
      write(x);
      write_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool write(tuple<T...> tpl) {
    write_tuple(tpl);
    return true;
  }
  template <class T, size_t S>
  void write(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if (val < 0) {
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if (negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  printer.write(head);
  if (sizeof...(Tail)) printer.write(' ');
  print(forward<Tail>(tail)...);
}

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "library/graph/base.hpp"

template <typename T>
struct Edge {
  int frm, to;
  T cost;
  int id;
};

template <typename T = int, bool directed = false>
struct Graph {
  int N, M;
  using cost_type = T;
  using edge_type = Edge<T>;
  vector<edge_type> edges;
  vector<int> indptr;
  vector<edge_type> csr_edges;
  vc<int> vc_deg, vc_indeg, vc_outdeg;
  bool prepared;

  class OutgoingEdges {
  public:
    OutgoingEdges(const Graph* G, int l, int r) : G(G), l(l), r(r) {}

    const edge_type* begin() const {
      if (l == r) { return 0; }
      return &G->csr_edges[l];
    }

    const edge_type* end() const {
      if (l == r) { return 0; }
      return &G->csr_edges[r];
    }

  private:
    const Graph* G;
    int l, r;
  };

  bool is_prepared() { return prepared; }
  constexpr bool is_directed() { return directed; }

  Graph() : N(0), M(0), prepared(0) {}
  Graph(int N) : N(N), M(0), prepared(0) {}

  void build(int n) {
    N = n, M = 0;
    prepared = 0;
    edges.clear();
    indptr.clear();
    csr_edges.clear();
    vc_deg.clear();
    vc_indeg.clear();
    vc_outdeg.clear();
  }

  void add(int frm, int to, T cost = 1, int i = -1) {
    assert(!prepared);
    assert(0 <= frm && 0 <= to && to < N);
    if (i == -1) i = M;
    auto e = edge_type({frm, to, cost, i});
    edges.eb(e);
    ++M;
  }

  // wt, off
  void read_tree(bool wt = false, int off = 1) { read_graph(N - 1, wt, off); }

  void read_graph(int M, bool wt = false, int off = 1) {
    for (int m = 0; m < M; ++m) {
      INT(a, b);
      a -= off, b -= off;
      if (!wt) {
        add(a, b);
      } else {
        T c;
        read(c);
        add(a, b, c);
      }
    }
    build();
  }

  void read_parent(int off = 1) {
    for (int v = 1; v < N; ++v) {
      INT(p);
      p -= off;
      add(p, v);
    }
    build();
  }

  void build() {
    assert(!prepared);
    prepared = true;
    indptr.assign(N + 1, 0);
    for (auto&& e: edges) {
      indptr[e.frm + 1]++;
      if (!directed) indptr[e.to + 1]++;
    }
    for (int v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; }
    auto counter = indptr;
    csr_edges.resize(indptr.back() + 1);
    for (auto&& e: edges) {
      csr_edges[counter[e.frm]++] = e;
      if (!directed)
        csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id});
    }
  }

  OutgoingEdges operator[](int v) const {
    assert(prepared);
    return {this, indptr[v], indptr[v + 1]};
  }

  vc<int> deg_array() {
    if (vc_deg.empty()) calc_deg();
    return vc_deg;
  }

  pair<vc<int>, vc<int>> deg_array_inout() {
    if (vc_indeg.empty()) calc_deg_inout();
    return {vc_indeg, vc_outdeg};
  }

  int deg(int v) {
    if (vc_deg.empty()) calc_deg();
    return vc_deg[v];
  }

  int in_deg(int v) {
    if (vc_indeg.empty()) calc_deg_inout();
    return vc_indeg[v];
  }

  int out_deg(int v) {
    if (vc_outdeg.empty()) calc_deg_inout();
    return vc_outdeg[v];
  }

  void debug() {
    print("Graph");
    if (!prepared) {
      print("frm to cost id");
      for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id);
    } else {
      print("indptr", indptr);
      print("frm to cost id");
      FOR(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id);
    }
  }

  // G における頂点 V[i] が、新しいグラフで i になるようにする
  Graph<T, directed> rearrange(vc<int> V) {
    int n = len(V);
    map<int, int> MP;
    FOR(i, n) MP[V[i]] = i;
    Graph<T, directed> G(n);
    for (auto&& e: edges) {
      if (MP.count(e.frm) && MP.count(e.to)) {
        G.add(MP[e.frm], MP[e.to], e.cost);
      }
    }
    G.build();
    return G;
  }

private:
  void calc_deg() {
    assert(vc_deg.empty());
    vc_deg.resize(N);
    for (auto&& e: edges) vc_deg[e.frm]++, vc_deg[e.to]++;
  }

  void calc_deg_inout() {
    assert(vc_indeg.empty());
    vc_indeg.resize(N);
    vc_outdeg.resize(N);
    for (auto&& e: edges) { vc_indeg[e.to]++, vc_outdeg[e.frm]++; }
  }
};
#line 4 "main.cpp"

void solve() {
  LL(N, M);
  vc<pi> edges;
  vc<set<int>> nbd(N);
  FOR(M) {
    INT(a, b);
    --a, --b;
    edges.eb(a, b);
    nbd[a].insert(b);
    nbd[b].insert(a);
  }

  vc<int> deg(N);
  FOR(v, N) deg[v] = len(nbd[v]);

  Graph<bool, 0> G(N);
  vc<int> nbd_leaf(N);
  FOR(v, N) if (deg[v] == 1) {
    for (auto&& to: nbd[v]) nbd_leaf[to]++;
  }
  if (MAX(nbd_leaf) >= 3) return;
  if (MIN(deg) == 0) return;

  auto can = [&](int a, int b) -> bool {
    FOR(2) {
      swap(a, b);
      if (deg[a] == 1) return 0;
      if (deg[a] >= 3) continue;
      for (auto&& to: nbd[a]) {
        if (to == b) continue;
        if (nbd_leaf[to] == 2) return 0;
      }
    }
    if (deg[a] == 2 && deg[b] == 2) {
      int xa = b, xb = a;
      for (auto&& t: nbd[a]) xa ^= t;
      for (auto&& t: nbd[b]) xb ^= t;
      if (xa == xb && nbd_leaf[xa] == 1) return 0;
    }
    return 1;
  };

  FOR(eid, M) {
    auto [a, b] = edges[eid];
    if (!can(a, b)) {
      G.add(a, b);
      continue;
    }
    deg[a]--, deg[b]--;
    nbd[a].erase(b), nbd[b].erase(a);
    FOR(2) {
      swap(a, b);
      if (deg[a] != 1) continue;
      for (auto&& to: nbd[a]) nbd_leaf[to]++;
    }
  }

  G.build();

  deg = G.deg_array();
  vc<int> S;
  FOR(v, N) if (nbd_leaf[v] >= 2) S.eb(v);

  vc<int> ANS(N, -1);
  array<int, 2> CNT = {0, 0};

  auto set_ans = [&](int v, int x) -> void { ANS[v] = x, CNT[x]++; };

  for (auto&& s: S) {
    vc<int> leaf, V0, V1;
    for (auto&& e: G[s]) {
      int to = e.to;
      if (deg[to] == 1) {
        leaf.eb(to);
      } else {
        for (auto&& f: G[to]) {
          if (f.to == s) continue;
          if (ANS[f.to] == -1) continue;
          if (ANS[f.to] == 0) V0.eb(to);
          if (ANS[f.to] == 1) V1.eb(to);
        }
      }
    }
    ll x0 = len(V0), x1 = len(V1);
    int me = (x0 < x1 ? 0 : 1);
    if (x0 == x1) me = (CNT[0] <= CNT[1] ? 1 : 0);
    set_ans(s, me);
    for (auto&& v: leaf) set_ans(v, me ^ 1);
    if (me == 0) {
      for (auto&& v: V0) set_ans(v, me ^ 1);
      for (auto&& v: V1) {
        if (CNT[0] <= CNT[1])
          set_ans(v, 0);
        else
          set_ans(v, 1);
      }
    }
    if (me == 1) {
      for (auto&& v: V1) set_ans(v, me ^ 1);
      for (auto&& v: V0) {
        if (CNT[0] <= CNT[1])
          set_ans(v, 0);
        else
          set_ans(v, 1);
      }
    }
    assert(abs(CNT[0] - CNT[1]) <= 1);
  }

  FOR(v, N) {
    if (ANS[v] != -1) continue;
    assert(deg[v] == 1);
    for (auto&& e: G[v]) { set_ans(v, 0), set_ans(e.to, 1); }
  }

  assert(MIN(ANS) >= 0);

  vc<int> A, B;
  FOR(v, N) if (ANS[v] == 0) A.eb(v);
  FOR(v, N) if (ANS[v] == 1) B.eb(v);
  if (len(A) > len(B)) swap(A, B);

  // check ans
  assert(len(A) == N / 2);
  vc<int> dp(N);
  FOR(v, N) {
    dp[v] |= 1 << ANS[v];
    for (auto&& e: G[v]) { dp[v] |= 1 << ANS[e.to]; }
    assert(dp[v] == 3);
  }

  for (auto&& x: A) ++x;
  print(A);
}

signed main() {
  INT(T);
  FOR(T) solve();

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3444kb

input:

2
6 7
1 2
1 3
2 3
3 4
4 5
4 6
5 6
3 2
1 2
2 3

output:

1 2 6
2

result:

ok ok (2 test cases)

Test #2:

score: 0
Accepted
time: 73ms
memory: 3640kb

input:

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

output:

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

result:

ok ok (10000 test cases)

Test #3:

score: 0
Accepted
time: 55ms
memory: 3840kb

input:

1000
337 338
164 11
138 75
114 262
170 298
166 241
269 24
9 134
233 60
50 222
231 253
296 242
173 18
93 223
116 151
312 150
82 236
180 20
297 184
268 70
334 162
217 135
258 321
80 209
212 208
18 163
227 104
334 135
77 118
17 230
307 105
307 335
29 24
111 177
324 24
85 3
214 191
310 182
22 171
202 21...

output:

2 6 11 19 23 28 29 31 32 36 37 38 40 41 42 45 57 62 64 69 71 76 79 82 85 87 93 94 95 97 98 99 102 108 110 114 115 118 119 122 125 128 131 132 133 136 137 142 146 147 148 151 152 153 158 161 162 165 167 169 172 173 176 177 180 181 183 185 186 187 188 191 192 196 201 203 204 205 206 208 209 210 211 21...

result:

ok ok (1000 test cases)

Test #4:

score: 0
Accepted
time: 57ms
memory: 6372kb

input:

100
1038 1044
206 546
372 853
526 57
777 72
645 866
15 716
254 707
366 753
635 809
850 407
616 149
839 175
320 770
649 686
857 798
1027 40
988 566
315 500
187 615
100 523
867 708
51 381
858 9
177 55
310 54
355 215
78 26
740 570
523 797
828 693
930 981
208 185
663 957
298 523
235 496
622 174
285 247
...

output:

1 3 5 6 7 8 9 10 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 37 38 39 40 41 43 45 46 47 48 50 51 54 55 57 59 60 61 63 64 66 67 69 70 71 76 77 78 79 80 82 83 84 86 87 88 90 91 93 94 95 97 98 100 102 103 105 108 109 110 111 112 115 116 118 119 121 122 125 126 127 128 129 130 131 132 13...

result:

ok ok (100 test cases)

Test #5:

score: 0
Accepted
time: 92ms
memory: 22088kb

input:

10
1380 1393
960 647
1319 708
57 1128
751 148
1291 602
835 921
942 406
622 616
967 91
555 545
871 10
447 471
1140 306
149 121
587 165
1179 936
256 787
332 374
729 129
631 481
976 86
1128 1300
477 776
460 313
538 632
1210 275
355 470
1324 885
870 1325
389 979
468 532
41 416
1026 243
1153 152
948 323
...

output:

1 2 3 5 7 8 9 10 11 12 13 15 17 19 20 21 22 23 25 26 27 28 29 32 33 35 36 39 40 41 42 44 45 46 50 51 52 53 54 56 57 58 59 61 63 64 66 67 68 69 72 73 74 75 78 79 80 82 83 84 85 87 88 89 90 91 92 93 95 96 97 98 100 101 102 103 104 105 106 107 109 110 111 112 113 115 117 118 119 121 123 125 126 127 129...

result:

ok ok (10 test cases)

Test #6:

score: 0
Accepted
time: 176ms
memory: 46920kb

input:

1
200000 201978
69113 28513
94227 164392
56849 195513
22579 149089
195084 193248
121765 162768
135432 101508
107443 89723
12337 87598
173450 107835
13160 161882
18965 179808
53739 23609
114567 23456
195251 178048
61586 87664
179364 25594
90158 169714
30104 161354
143346 4279
177208 87389
122480 1269...

output:

2 3 4 5 6 7 8 9 10 11 12 13 15 17 18 19 20 21 22 24 25 26 27 30 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 52 53 54 55 57 60 61 62 63 64 65 67 69 71 72 73 75 76 78 79 80 81 82 83 84 85 86 91 92 93 94 95 96 97 99 100 101 102 104 106 107 108 109 110 111 113 114 115 116 117 118 120 121 12...

result:

ok ok (1 test case)

Test #7:

score: 0
Accepted
time: 75ms
memory: 3636kb

input:

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

output:

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

result:

ok ok (10000 test cases)

Test #8:

score: 0
Accepted
time: 93ms
memory: 3604kb

input:

10000
11 13
6 3
9 4
10 4
9 6
10 7
1 5
2 11
2 8
10 6
2 9
6 7
2 5
5 11
3 2
2 1
2 3
2 1
2 1
12 14
12 11
10 7
5 6
2 5
5 8
8 3
8 1
3 12
12 7
2 10
10 11
6 4
11 2
9 3
4 4
1 2
1 3
4 3
2 3
11 13
3 7
1 5
1 6
8 5
9 7
1 2
1 11
2 4
10 9
10 1
7 2
8 3
8 6
2 1
1 2
15 18
3 11
2 10
7 14
14 4
7 3
6 11
15 12
5 11
2 7
7...

output:

1 2 6 10 11
2
1
1 3 4 5 7 11
1 3
1 4 7 8 10
1
3 6 7 8 12 14 15
3 5 6 7 9 11 12 15 16 17 19 21 22 23 24 25 27 28 30 31 32 34 36 38 40 44 48 49 52 56 57 59 64
4 5 6 10 11 13
2 6 7 8
2 8 11 12 15 16 20 22 23 24 25 27 31 32 34 35 37 38 39
4 5 7 13 15 17 22 26 27 33 34 37 38 43 44 47 48 52 53 54 56 58 60...

result:

ok ok (10000 test cases)

Test #9:

score: 0
Accepted
time: 105ms
memory: 3688kb

input:

10000
10 14
4 9
5 10
1 10
7 6
8 6
9 6
8 3
8 7
4 6
5 3
10 4
10 2
4 8
1 9
6 8
1 2
5 2
5 1
3 4
5 3
6 5
2 3
3 1
3 3
2 1
3 2
3 1
18 26
18 3
10 11
2 4
17 4
8 12
14 15
1 12
13 12
15 7
13 15
14 2
17 5
1 13
11 16
9 3
13 9
6 12
11 14
3 4
3 11
7 11
8 2
8 4
15 6
12 10
12 18
24 35
18 4
22 10
1 21
22 6
23 7
6 14
...

output:

1 2 3 4 7
2 4 5
3
2 3 5 6 8 10 11 13 18
1 2 5 6 7 9 10 13 17 18 19 21
1 2 4 5 6 7 8 9 10 11 13 14 15 17 18 19 20 21 22 23 25 27 28 30 35 41 45 47 50 55 58 64 66
2 4 5 7 8 12
3 5 11 14 17 18 19 20 21 22 24 26 28 30 31 32
3 4 7 8
4 8 9 10 12 13
4 5 6 10 12 14 17 18 19 20 22 23 24 25 26 27 29 31 34 37 ...

result:

ok ok (10000 test cases)

Test #10:

score: 0
Accepted
time: 133ms
memory: 3684kb

input:

10000
4 6
1 3
2 3
4 2
4 1
1 2
4 3
25 51
19 15
19 10
12 3
9 7
5 4
7 21
25 12
20 16
1 13
20 14
15 12
20 13
8 5
16 9
17 13
3 25
25 20
16 22
4 8
5 7
9 10
5 11
4 24
13 21
9 4
15 24
16 11
13 4
22 21
4 14
20 10
12 6
1 4
3 18
9 6
5 2
24 3
16 4
6 16
25 16
21 16
22 25
3 21
10 15
25 23
1 19
7 15
15 20
19 14
17...

output:

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

result:

ok ok (10000 test cases)

Test #11:

score: 0
Accepted
time: 153ms
memory: 3684kb

input:

10000
24 60
13 22
6 12
21 17
24 8
15 11
18 19
17 7
24 1
18 16
21 2
17 12
21 11
10 7
9 18
6 21
17 10
3 24
16 12
7 23
11 8
22 24
3 17
23 3
1 12
8 5
4 24
15 13
8 22
2 8
13 17
10 2
2 7
7 18
18 14
22 20
13 6
5 16
22 23
21 22
5 24
21 14
1 7
12 20
24 20
8 14
17 11
1 19
17 8
9 10
1 11
14 13
10 15
19 11
14 2...

output:

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

result:

ok ok (10000 test cases)

Test #12:

score: 0
Accepted
time: 69ms
memory: 3840kb

input:

1000
53 57
47 22
30 20
37 51
19 4
39 22
29 53
1 11
53 18
33 52
29 2
21 50
42 50
42 49
36 44
37 16
5 24
52 35
8 36
28 29
9 24
24 34
32 37
44 46
31 2
13 45
5 21
3 19
17 47
14 35
33 43
43 27
48 13
16 12
33 30
26 14
8 49
41 27
43 45
6 9
36 22
20 37
38 5
17 25
3 7
42 3
33 10
23 50
1 14
40 24
45 42
48 52
...

output:

2 5 7 9 10 11 13 14 16 18 19 22 25 29 30 34 37 40 41 45 46 47 49 50 52 53
2 9 11 13 15 16 20 22 30 32 34 36 38 40 41 42 43 44 45 46 47 49 51 52 53 55 56 57 59
1 2 3 4 5 6 8 9 10 11 13 14 17 18 19 20 21 22 23 24 25 26 27 30 31 32 33 34 38 40 41 42 44 45 52 54 55 57 58 59 60 61 63 65 67 70 73 75 78 79...

result:

ok ok (1000 test cases)

Test #13:

score: 0
Accepted
time: 87ms
memory: 3868kb

input:

1000
137 178
124 131
53 109
99 21
107 122
79 28
80 88
126 9
16 1
29 55
126 54
13 39
135 16
63 56
123 121
27 74
81 95
34 38
49 85
127 135
87 106
91 68
57 124
122 113
87 1
52 104
135 93
132 12
98 83
85 26
66 76
41 82
108 90
88 59
29 15
75 58
36 14
116 65
83 64
21 105
132 13
7 70
97 127
92 112
126 55
1...

output:

4 8 10 18 19 25 27 29 31 36 43 48 49 50 51 52 55 57 58 59 62 63 71 77 79 80 82 83 85 87 88 89 90 91 92 93 95 96 97 100 101 102 103 105 106 107 110 111 112 113 115 116 117 118 119 120 123 125 127 128 129 131 132 133 134 135 136 137
1 3 4 5 6 8 9 10 11 12 15 16 22 24 26 29 30 31 32 34 37 39 40 42 48
4...

result:

ok ok (1000 test cases)

Test #14:

score: 0
Accepted
time: 95ms
memory: 3948kb

input:

1000
148 221
51 9
45 80
86 44
133 98
100 25
130 4
99 17
28 44
131 87
103 87
102 53
115 49
9 5
105 130
11 69
56 23
148 106
106 85
57 102
15 147
100 52
22 10
138 60
38 12
126 119
12 125
86 62
108 123
15 63
90 93
35 116
1 75
63 126
23 127
143 127
114 24
12 133
144 82
12 29
6 51
67 26
129 79
115 16
53 6...

output:

2 3 5 6 7 9 10 11 12 13 14 15 16 17 20 22 26 27 30 31 32 33 35 36 37 38 41 43 44 45 48 49 51 52 53 54 56 58 60 62 63 65 71 72 76 79 80 81 83 84 85 87 89 93 94 97 103 105 106 107 108 109 111 121 122 126 129 130 132 134 137 142 144 145
1 5 6 7 11 20 21 27 29 30 31 32 33 38 39 40 42 44 45 46 47 48 49 5...

result:

ok ok (1000 test cases)

Test #15:

score: 0
Accepted
time: 127ms
memory: 3864kb

input:

1000
527 1061
464 254
106 364
251 82
282 81
152 454
399 114
527 289
430 519
202 320
177 302
398 55
358 181
495 240
86 426
113 171
201 262
82 336
403 77
266 21
176 132
14 97
139 137
479 397
153 403
156 308
105 28
109 272
294 170
336 508
439 105
259 101
429 441
118 200
189 56
297 184
457 385
248 334
4...

output:

2 3 5 10 15 26 27 32 41 42 48 50 56 59 63 64 66 70 73 75 79 80 81 89 91 92 98 100 101 103 106 107 109 114 117 120 125 132 135 138 139 140 142 143 146 148 149 150 152 155 161 166 167 169 170 174 176 178 179 182 184 185 186 187 190 191 194 199 200 202 203 207 208 209 211 215 216 219 220 221 223 224 22...

result:

ok ok (1000 test cases)

Test #16:

score: 0
Accepted
time: 153ms
memory: 3992kb

input:

1000
24 59
14 16
17 22
19 4
3 21
15 11
4 15
24 6
12 18
15 19
6 17
6 3
19 6
17 18
24 12
3 8
13 8
3 19
22 19
20 18
2 14
16 9
22 15
19 8
22 4
10 7
11 3
22 3
8 12
11 17
24 13
8 21
22 9
13 18
9 12
19 5
10 22
23 3
21 20
4 24
1 15
21 23
18 7
5 22
1 11
22 16
16 24
1 20
20 4
5 23
10 3
7 8
20 9
9 6
23 24
14 9...

output:

1 2 3 4 6 7 11 12 13 16 17 23
3 11 16 17 19 23 26 27 30 33 34 35 38 42 45 50 52 55 58 60 63 66 68 70 74 76 78 80 81 82 84 86 87 89 90 91 92 94 95 97 98 101 102 104 105 106 107 108 109 110 112 113 115 116 117 118 119 120 122 123 125 126 127
4 9 11 13 15 22 25 26 30 31 39 40 42 45 46 51 55 57 63 66 67...

result:

ok ok (1000 test cases)

Test #17:

score: 0
Accepted
time: 68ms
memory: 5908kb

input:

100
1400 1550
949 973
216 1089
101 284
568 543
878 648
1125 1117
1052 486
1260 1161
1397 54
1005 922
483 168
202 152
899 685
978 388
1223 1178
1109 239
932 415
105 28
596 251
357 865
842 224
887 1053
304 484
697 780
1164 193
411 798
1267 1395
40 166
21 1027
814 742
905 354
1332 1346
86 1274
726 73
4...

output:

1 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 24 25 26 27 29 30 32 33 34 36 37 40 41 43 44 46 47 48 49 50 51 52 53 55 57 59 60 61 62 65 66 68 69 70 72 74 76 77 79 80 82 83 84 85 86 88 89 91 92 98 99 100 102 103 105 106 107 108 109 110 111 113 114 115 117 118 119 120 122 123 124 125 126 129 130 131 1...

result:

ok ok (100 test cases)

Test #18:

score: 0
Accepted
time: 85ms
memory: 7028kb

input:

100
15151 19865
9599 11515
2453 4807
12417 12980
8787 12984
2666 3990
7030 3605
13780 1990
6564 14035
12745 5300
9179 9047
1105 8795
13193 2009
2347 3783
4282 2640
8744 2083
12968 1734
111 1688
14899 11212
11013 15151
4326 6532
9261 10694
8013 10608
8980 9408
379 3570
5827 13496
273 14106
1090 12649...

output:

4 5 6 13 18 20 25 27 28 29 31 42 43 50 53 55 58 63 64 65 69 73 74 75 89 97 99 102 104 107 123 129 136 146 147 155 157 159 161 163 167 170 174 175 183 185 186 191 193 198 202 203 211 212 218 219 226 227 236 241 243 246 253 255 260 261 264 266 269 271 275 281 285 286 288 289 292 296 300 304 309 312 31...

result:

ok ok (100 test cases)

Test #19:

score: 0
Accepted
time: 101ms
memory: 6260kb

input:

100
1387 2091
632 868
379 1372
1247 788
72 562
1014 374
677 436
478 1033
997 896
1016 925
291 450
458 392
91 65
380 135
318 757
471 281
390 874
752 953
401 688
978 284
1276 639
565 1356
368 1259
673 639
283 551
647 94
125 1097
1055 672
538 1183
998 813
391 27
1066 766
782 1323
1220 164
427 819
274 5...

output:

2 3 11 14 17 20 28 29 32 33 37 38 39 41 43 46 47 48 55 59 63 66 69 70 71 72 73 76 82 83 84 86 89 94 100 103 105 110 113 116 117 121 122 132 133 134 135 136 140 142 145 146 149 152 167 170 173 180 181 183 191 192 193 197 198 205 210 222 223 224 227 228 232 234 241 244 245 249 254 259 260 263 265 268 ...

result:

ok ok (100 test cases)

Test #20:

score: 0
Accepted
time: 131ms
memory: 6192kb

input:

100
515 1036
358 355
124 512
414 420
214 74
423 447
344 263
431 482
364 446
314 200
299 244
389 507
191 58
85 405
130 57
288 370
231 324
442 405
324 42
453 137
312 167
33 67
443 27
497 101
447 442
211 438
200 210
472 219
462 227
210 19
416 76
483 374
48 374
259 264
331 214
486 213
146 254
264 350
36...

output:

3 5 6 15 18 20 21 22 24 30 32 33 34 37 45 59 66 67 74 75 76 77 78 79 82 84 86 88 89 92 97 98 100 105 113 115 117 119 123 125 134 137 139 141 144 145 148 149 153 157 158 164 168 169 171 172 173 176 186 189 190 191 192 193 195 197 198 199 201 202 203 205 206 210 211 213 215 220 222 223 224 225 228 231...

result:

ok ok (100 test cases)

Test #21:

score: 0
Accepted
time: 175ms
memory: 6888kb

input:

100
985 2463
916 513
388 126
199 847
456 244
218 236
243 961
588 899
242 137
98 45
273 505
332 492
828 494
368 889
551 617
662 87
651 450
645 884
49 487
731 934
328 482
224 101
590 687
80 972
143 154
420 155
113 886
413 716
841 402
334 374
549 893
62 743
964 386
608 294
124 692
213 980
857 886
228 6...

output:

4 8 9 11 14 16 17 21 25 27 30 36 45 52 53 54 58 59 60 61 64 66 69 77 83 84 85 88 89 92 96 100 101 102 104 108 116 118 123 125 126 130 134 135 139 144 145 149 152 155 165 167 171 174 175 178 184 185 186 187 188 189 190 191 195 196 197 198 205 206 207 208 212 222 226 236 238 243 249 253 254 256 257 26...

result:

ok ok (100 test cases)

Test #22:

score: 0
Accepted
time: 95ms
memory: 20780kb

input:

10
6620 7333
1646 5207
3808 6296
3890 1170
841 4461
3269 5613
3427 743
4429 351
6077 6488
1639 2661
704 600
1959 6216
4631 689
62 659
1849 1253
2888 6071
823 3326
4491 1670
4620 1541
2403 1275
5905 998
6515 5675
5204 2518
2 6397
5388 5626
1712 3996
6069 3525
962 4452
5528 5749
5292 1334
4864 4469
21...

output:

1 2 3 5 6 8 10 11 13 14 16 17 19 20 22 23 25 26 27 28 32 33 34 35 36 39 40 41 42 43 44 45 47 49 50 51 52 54 55 56 57 58 60 61 62 63 64 65 66 67 68 69 71 72 73 74 78 79 80 83 84 85 87 88 90 91 93 94 95 96 97 100 103 105 106 107 108 109 110 111 113 114 115 116 118 120 121 122 123 124 127 128 129 130 1...

result:

ok ok (10 test cases)

Test #23:

score: 0
Accepted
time: 118ms
memory: 19108kb

input:

10
31631 41405
12464 26816
7161 23441
26603 26999
3101 17725
19057 12144
25877 18100
27212 15122
23942 15607
10953 6392
8135 30928
10824 21016
16740 16082
31166 11527
30093 3178
18953 11904
16873 18594
31034 21707
18284 11028
10289 6972
4229 16452
6726 8826
15758 31430
30272 23869
31004 31424
15626 ...

output:

4 6 10 11 14 17 18 20 25 26 33 41 43 45 46 51 54 57 59 64 67 77 78 79 90 91 92 95 102 105 113 117 119 123 125 130 144 145 153 155 158 159 161 165 166 169 170 175 178 180 187 190 191 192 197 201 202 209 214 216 218 219 225 233 235 238 239 245 246 247 250 255 261 271 276 277 283 284 285 288 291 294 29...

result:

ok ok (10 test cases)

Test #24:

score: 0
Accepted
time: 136ms
memory: 18732kb

input:

10
28538 43099
13200 13914
26716 18327
28186 28518
1215 11877
11167 9447
24145 13428
13894 1222
12303 4558
7451 3511
24131 6746
3501 5306
13827 16899
19501 15623
18276 4006
16371 3015
3638 27140
3419 28191
649 11619
7330 19380
3215 17183
13519 12575
3643 1100
23996 5666
7650 3931
11863 18905
11099 2...

output:

2 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 23 24 25 27 28 29 30 32 34 35 37 38 39 40 41 42 43 44 45 47 48 50 53 54 55 57 58 59 60 61 63 64 66 67 68 69 70 71 72 73 75 76 78 79 80 81 83 85 87 88 89 90 91 92 93 94 95 96 97 98 100 101 102 103 104 105 106 108 109 110 112 113 114 115 116 117 119 120 1...

result:

ok ok (10 test cases)

Test #25:

score: 0
Accepted
time: 239ms
memory: 31632kb

input:

10
87788 176493
85411 2449
75677 87148
41863 8856
26947 41851
69142 52475
19624 254
68187 45850
1914 1328
60252 34269
74977 29820
84340 25888
15811 3705
1188 51146
923 7500
4632 78262
79717 73522
51839 29805
50741 81652
34291 1102
47663 68963
8687 86118
17441 86354
11708 6564
87269 85939
81969 15769...

output:

2 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 27 28 29 30 31 32 33 34 35 36 37 38 39 40 42 43 44 45 46 47 48 49 50 53 54 55 56 57 58 59 60 61 62 63 64 65 67 68 69 70 71 73 74 75 78 80 81 82 83 84 86 87 88 89 90 91 92 93 94 96 97 98 99 100 102 103 104 105 106 108 110 111 113 115 116 118 121...

result:

ok ok (10 test cases)

Test #26:

score: 0
Accepted
time: 237ms
memory: 18452kb

input:

10
8816 22043
7419 5025
5365 4666
3322 7417
5863 5973
2641 1448
6401 2157
1667 7379
6833 7402
5527 5022
2651 4669
4676 5212
3876 2581
5037 6774
2606 6661
5930 519
3836 8394
1159 3510
2789 2327
5496 4249
5240 4702
4006 7011
5102 1260
2708 1364
8618 888
3465 3208
5175 3282
5081 6716
5593 1814
2896 663...

output:

1 3 4 6 7 9 10 11 12 14 15 17 18 20 21 22 23 24 27 28 29 31 32 33 35 36 37 39 41 42 43 44 47 51 52 53 54 55 56 57 58 61 62 63 64 65 66 67 72 73 75 76 78 79 80 81 82 83 84 85 86 87 91 92 93 94 95 96 97 98 99 100 101 102 105 106 109 110 112 113 114 115 116 118 119 120 121 122 125 128 130 131 133 134 1...

result:

ok ok (10 test cases)

Test #27:

score: 0
Accepted
time: 195ms
memory: 49072kb

input:

1
200000 222059
53595 110970
173632 131224
18782 129709
79934 195396
42423 87939
191850 58500
75657 76504
130760 155268
40793 74463
110561 181427
166061 166730
169476 19173
54038 80930
98140 20017
131017 7357
135665 51329
20673 95904
15527 156410
147735 107963
185611 9516
181066 181938
6507 122388
3...

output:

1 4 7 8 12 13 14 15 16 17 18 20 22 24 25 27 28 30 31 32 34 36 37 39 41 42 43 46 47 48 49 52 53 54 55 57 58 59 60 61 64 66 67 69 70 72 74 76 77 79 81 82 84 85 88 89 91 92 93 94 95 97 99 100 101 102 103 104 105 106 107 110 111 113 114 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132...

result:

ok ok (1 test case)

Test #28:

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

input:

1
200000 262063
72841 66604
94581 51837
191542 123743
149876 10516
128822 123410
139111 103089
158541 56483
183570 157423
128256 118508
92821 129228
163748 28520
2448 160970
37107 90515
139799 163596
184374 16626
78012 98010
144666 155211
146459 60321
62391 172660
124463 39432
99102 80299
22916 1273...

output:

1 2 3 4 5 7 9 10 11 12 14 15 16 18 21 22 24 26 27 28 29 30 32 33 34 35 36 37 39 40 41 42 43 45 46 47 48 50 51 52 53 55 56 58 59 60 61 62 63 64 65 69 70 73 75 76 77 78 79 81 82 83 84 86 87 89 90 92 93 94 96 97 98 99 100 101 102 104 105 106 107 108 111 112 114 115 116 119 120 122 124 125 127 128 129 1...

result:

ok ok (1 test case)

Test #29:

score: 0
Accepted
time: 318ms
memory: 57928kb

input:

1
200000 301952
21951 38377
145264 141899
20286 189141
49248 10797
131312 186634
193391 7330
90758 178447
133654 28458
197098 132935
142271 123768
182413 51079
106749 37339
80111 160519
130329 80747
134297 17746
89135 104031
76611 66916
13891 148818
166668 148476
177606 78551
133202 121415
17109 114...

output:

1 3 4 5 7 9 10 11 12 13 15 16 18 19 21 22 23 24 25 26 27 28 29 30 31 33 34 35 39 40 42 43 44 46 47 48 49 50 52 53 54 55 56 58 59 61 62 63 64 65 66 67 68 69 71 72 73 76 77 78 80 82 83 84 87 88 89 93 94 95 97 98 99 102 103 106 107 109 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127...

result:

ok ok (1 test case)

Test #30:

score: 0
Accepted
time: 430ms
memory: 68740kb

input:

1
200000 402105
169412 28307
39235 94949
120109 190352
59500 104359
75817 175560
50253 41771
83195 186648
20091 175725
106263 65825
156850 28786
72265 77440
104707 152961
108429 140785
176083 164531
173958 160585
89283 97448
72968 178690
182706 163213
64471 47768
59578 23108
25972 130392
101827 1729...

output:

1 4 5 6 7 10 11 12 13 14 17 18 20 21 22 24 26 27 28 29 31 32 35 36 37 38 39 40 41 42 46 47 48 49 52 53 54 56 57 59 61 63 64 69 70 71 72 73 75 76 78 80 81 83 84 86 87 89 90 92 94 95 96 97 98 99 101 102 103 105 107 108 109 110 111 112 113 114 115 116 120 121 122 123 124 125 130 131 134 135 137 140 141...

result:

ok ok (1 test case)

Test #31:

score: 0
Accepted
time: 619ms
memory: 79304kb

input:

1
200000 499981
80537 142045
166196 27324
188484 59794
73011 62848
54982 32788
146891 120397
145977 112297
30732 34355
198025 193511
46734 37750
74321 75081
38173 123072
90782 51316
3345 153541
108762 97369
16828 137609
157439 191613
162866 51112
72589 170889
126524 133464
82570 115809
128563 112379...

output:

4 5 7 8 9 10 12 13 14 15 17 18 20 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 40 42 43 44 45 46 47 48 49 50 51 54 56 58 59 60 61 62 63 64 66 67 68 69 70 71 73 74 75 76 78 79 80 81 82 83 84 86 87 88 89 91 92 93 95 96 97 98 99 100 101 104 105 106 107 108 109 111 112 115 116 118 119 120 121 123 124 12...

result:

ok ok (1 test case)

Test #32:

score: 0
Accepted
time: 122ms
memory: 3600kb

input:

10000
9 14
7 9
6 7
6 3
3 2
3 5
3 4
3 8
7 8
2 7
4 7
3 1
7 1
7 5
9 3
5 4
2 3
4 5
4 1
2 1
65 120
48 33
48 27
65 28
21 48
48 4
3 28
39 48
48 10
48 50
32 13
19 48
52 24
48 24
48 15
48 31
65 48
52 19
60 48
49 41
22 28
48 20
18 48
2 28
25 48
1 48
2 48
28 23
52 20
28 51
28 11
52 63
59 28
28 36
48 44
31 28
2...

output:

2 3 4 5
2 5
3 9 12 15 20 24 25 26 28 29 30 32 34 36 37 39 40 42 43 44 45 46 52 54 56 57 58 59 60 62 64 65
4 5 7 8 9 12 13 17 18 20 21 23 25 26 31 33 34
1 4 5
5 6 7 9 11 12
1 2 3 11 14 15 16 17 19
1 3 4 8 10 11 14 16 18 19 21 22
1 3 7 9 10 12
1 8 9 10 11
3
2 4 5 8 11 12 14
2 6 7
1 5 6 7 8 10
2 3 8 10...

result:

ok ok (10000 test cases)

Test #33:

score: 0
Accepted
time: 138ms
memory: 3916kb

input:

1000
65 124
10 5
5 16
64 33
3 59
4 59
50 5
60 33
5 39
55 59
33 61
5 8
5 49
31 33
5 41
37 59
5 48
23 59
34 33
59 17
22 5
33 47
11 5
59 38
5 45
5 13
63 5
5 14
5 2
33 16
40 5
27 33
5 64
59 49
41 33
25 59
28 33
65 59
59 11
33 62
15 33
59 35
59 14
53 59
33 29
30 5
44 33
62 5
33 32
50 59
59 30
59 45
42 59...

output:

1 5 6 8 10 11 13 14 15 16 20 21 22 23 25 27 28 30 34 38 39 42 43 44 46 50 51 52 54 55 56 61
2 3 4 5 7 9 11 14 15 19 20 24 27 29 30 32 34 36 37 39 40 43 44 46 47 51 53 55 57 59 61 64 65 67 72 73 74 75 77 81 85 89 92 93 96 97 98 102 103 105 110 114 116 117 118 120 121 122 123 127 128 129 132 133 135 1...

result:

ok ok (1000 test cases)

Test #34:

score: 0
Accepted
time: 143ms
memory: 7304kb

input:

100
2720 5430
15 549
864 1152
549 492
1152 2121
366 1608
2226 1574
2096 1152
951 1152
279 1278
1574 232
2537 1152
806 1278
1988 1152
1574 2203
1239 1278
414 549
434 549
549 2020
1608 1319
2464 1574
1232 1152
1608 728
1453 1152
992 1608
1608 1637
1242 1152
1190 1574
1278 1587
2105 1278
2577 549
1178 ...

output:

2 7 8 9 13 17 18 19 22 25 26 27 30 31 32 33 35 37 38 39 40 41 44 46 48 49 53 55 56 60 62 71 74 76 77 79 81 84 86 88 89 95 98 99 101 102 103 104 106 109 110 112 114 115 119 121 123 127 130 131 134 137 143 144 146 147 148 150 151 153 154 155 157 158 159 160 161 163 165 167 170 172 175 176 177 180 181 ...

result:

ok ok (100 test cases)

Test #35:

score: 0
Accepted
time: 244ms
memory: 25256kb

input:

10
11424 22838
10124 2930
2930 8210
6044 2930
9338 5243
2930 1990
8267 335
11369 2930
3640 2930
2930 8394
2930 4490
10225 5027
2930 7034
336 10225
6591 10225
2723 8267
3141 8267
9338 8308
8267 7647
2930 1471
9338 742
10225 2977
8267 4214
10232 6130
5050 6130
3536 9338
9338 810
8267 6841
8267 4313
59...

output:

1 3 6 7 8 9 12 13 15 16 17 19 20 21 25 26 28 29 33 38 39 46 47 48 50 51 53 55 58 62 63 64 65 68 69 74 75 77 78 79 86 87 91 92 93 95 97 99 100 102 103 104 107 108 109 110 113 114 115 116 117 119 120 121 122 123 124 125 128 133 135 136 142 145 147 149 150 152 153 154 156 157 159 160 164 168 171 172 17...

result:

ok ok (10 test cases)

Test #36:

score: 0
Accepted
time: 521ms
memory: 81072kb

input:

1
200000 399988
171813 28023
127391 157678
139161 157678
157678 158661
157678 6685
120596 157678
189440 28023
72845 28023
28023 155435
178088 157678
54821 157678
199920 7797
7797 23002
132615 7797
7797 114612
28023 98270
157678 29354
29544 28023
28023 6304
28023 86497
20726 7797
198021 7797
4578 157...

output:

2 4 7 8 10 12 13 15 18 20 21 24 26 27 29 30 32 33 35 39 41 43 47 53 54 57 58 59 60 61 62 63 67 68 69 70 71 73 75 76 77 78 79 80 84 85 87 93 95 96 97 101 103 104 107 108 109 110 111 112 113 115 123 124 125 130 132 133 136 137 138 139 141 144 145 147 149 150 153 154 158 159 160 162 169 171 172 175 177...

result:

ok ok (1 test case)

Test #37:

score: 0
Accepted
time: 475ms
memory: 81116kb

input:

1
200000 399994
17358 78776
138799 189702
78776 115828
78776 76870
189702 82466
80014 189702
78776 129553
14969 78776
161279 120022
103978 161279
189702 90678
65648 78776
164898 189702
78776 4880
189702 17932
189702 29494
71164 78776
55663 78776
78776 25638
78776 51965
78776 73585
189702 190545
1173...

output:

2 6 7 10 12 13 15 16 19 20 21 22 26 27 28 29 30 32 33 35 36 37 39 41 42 45 46 48 49 52 53 56 57 58 59 61 63 64 65 66 68 70 71 73 74 75 77 78 80 81 83 84 85 86 89 90 91 93 94 96 97 100 101 102 105 107 111 112 118 122 123 126 129 131 132 136 137 139 140 141 143 144 145 149 150 154 155 156 159 161 162 ...

result:

ok ok (1 test case)

Test #38:

score: 0
Accepted
time: 503ms
memory: 81216kb

input:

1
200000 399996
43234 184957
104384 184957
184957 104551
48901 184957
130388 184957
184957 191112
93746 184957
51488 83793
46496 184957
184957 149525
48305 51488
16545 51488
155037 184957
51488 99541
5545 184957
184957 50631
147758 184957
141234 51488
33945 184957
119044 51488
99610 51488
162526 514...

output:

1 3 4 5 6 7 10 12 13 14 15 16 18 19 21 23 25 26 28 29 31 32 33 38 40 42 43 50 51 54 56 58 60 61 63 64 65 66 69 70 72 74 77 78 82 85 86 88 90 91 92 94 101 102 103 104 105 107 108 109 111 113 118 119 120 125 126 129 132 133 134 137 141 144 145 148 149 151 152 153 157 159 161 163 164 166 167 168 169 17...

result:

ok ok (1 test case)

Test #39:

score: 0
Accepted
time: 489ms
memory: 81064kb

input:

1
200000 399994
187117 14028
171699 93144
87566 171699
48194 171699
123842 171699
86963 78638
171699 77033
187117 79890
123219 171699
171699 63678
68921 187117
187117 91518
12750 187117
11203 171699
166545 171699
187117 75563
4708 187117
86963 26711
115930 86963
187117 102050
187117 66412
187117 962...

output:

2 4 6 7 9 11 13 14 16 18 20 22 23 26 29 33 35 37 38 40 41 42 47 49 53 54 56 57 59 60 66 68 70 71 73 75 84 85 87 89 92 94 105 108 109 110 112 115 116 117 118 119 120 121 123 124 125 126 129 135 136 137 140 141 142 145 147 148 151 155 156 157 159 160 161 162 164 166 167 168 169 171 172 174 175 179 180...

result:

ok ok (1 test case)

Test #40:

score: 0
Accepted
time: 473ms
memory: 81128kb

input:

1
200000 399996
158442 44824
102533 158442
144188 158442
180888 177991
158442 60658
130921 158442
11093 158442
158442 91269
177991 66366
45320 177991
852 158442
158345 177991
177991 101419
177991 60694
77523 177991
158442 64839
177991 97717
158442 15688
101326 177991
57416 158442
105648 158442
15844...

output:

2 6 7 11 12 16 17 19 20 22 24 26 27 28 30 31 32 34 36 40 44 45 49 50 51 52 53 56 57 58 61 62 63 65 66 72 76 77 78 79 80 82 84 86 87 88 89 94 97 98 99 103 107 108 110 114 118 119 121 122 124 125 131 132 135 136 137 139 140 143 144 147 151 154 157 158 161 162 163 164 165 166 169 171 174 176 180 183 18...

result:

ok ok (1 test case)

Test #41:

score: 0
Accepted
time: 471ms
memory: 80888kb

input:

1
200000 399984
132326 109212
15458 104058
141635 150556
42757 160742
104058 183026
140555 176509
105281 104058
98409 123058
115963 132326
110622 160742
124231 104058
9948 132326
149792 132326
186350 132326
114248 132326
117808 104058
149757 178717
20007 132326
103768 104058
160742 132129
181418 132...

output:

3 5 7 13 14 18 19 24 27 28 31 32 34 36 37 39 41 42 44 45 48 49 52 53 63 64 67 68 70 72 73 74 75 77 79 80 81 84 87 88 92 96 97 99 100 102 105 106 107 108 109 110 111 112 115 120 121 123 125 126 127 128 131 132 133 135 136 137 138 139 140 144 145 146 147 148 149 150 151 152 155 156 158 160 161 162 164...

result:

ok ok (1 test case)

Test #42:

score: 0
Accepted
time: 484ms
memory: 80800kb

input:

1
200000 399938
118765 169368
80877 55756
183643 55120
179690 39975
52846 39431
183643 142616
40237 9287
169765 51704
169765 196513
180903 78049
2468 127986
103196 92043
171000 183643
51970 16065
33387 150171
54791 100228
96040 51970
183643 73275
194778 116171
119619 51970
78820 25947
121977 74719
1...

output:

1 3 5 7 11 13 15 16 18 19 20 21 22 25 27 30 33 34 35 36 38 39 41 43 45 46 48 49 50 51 52 53 54 55 57 58 59 62 63 66 68 69 70 71 72 74 76 80 83 84 85 86 88 91 92 93 99 102 104 105 107 110 111 112 115 118 125 126 129 131 132 133 134 136 142 143 148 149 153 154 157 162 164 166 167 168 169 170 171 174 1...

result:

ok ok (1 test case)

Test #43:

score: 0
Accepted
time: 521ms
memory: 80856kb

input:

1
200000 399918
4808 186087
3193 20269
53579 193832
181866 119189
96009 51067
26071 110895
180290 198389
75156 67809
146896 88504
26232 199270
41761 194173
163583 73217
11161 69425
127108 172920
26071 136318
4808 20765
58003 13956
56475 127108
124690 96369
98349 88504
88504 129805
1116 75156
193832 ...

output:

4 7 8 9 12 13 15 16 17 20 22 24 26 27 28 36 38 39 40 43 45 46 53 56 59 60 62 63 66 67 70 72 78 80 82 84 85 86 89 91 93 94 98 99 100 101 104 106 107 108 110 112 116 118 119 120 125 127 132 133 136 137 138 140 141 142 144 146 147 148 151 152 154 156 159 161 162 166 168 171 173 175 176 179 180 181 183 ...

result:

ok ok (1 test case)

Test #44:

score: 0
Accepted
time: 501ms
memory: 80344kb

input:

1
200000 394970
67823 148797
176646 48645
130521 57454
24214 159679
58899 105974
31385 9900
98402 172520
136909 143412
104381 107770
158622 39611
181123 4031
93760 67853
87239 94179
102524 50092
53452 91220
161571 173978
140608 6827
8215 91048
101935 80437
20495 175157
85578 193822
117607 100231
195...

output:

1 3 4 5 6 7 8 9 11 12 14 17 19 20 22 23 24 25 26 27 28 31 32 38 39 41 43 45 47 49 50 56 58 59 62 63 65 68 69 71 72 74 79 84 85 90 91 93 95 97 100 101 104 105 107 110 111 115 118 121 122 124 125 126 128 130 134 136 138 144 147 148 149 151 152 153 154 157 159 162 163 165 166 171 172 174 176 180 183 18...

result:

ok ok (1 test case)

Test #45:

score: 0
Accepted
time: 356ms
memory: 66272kb

input:

1
200000 324098
195943 81674
197522 192121
73692 10625
137597 30541
116880 163679
19609 78824
65138 65608
122246 18120
69217 48636
96269 102482
152468 42380
70492 187039
106990 158537
130005 170494
6227 16267
17532 42444
156564 89378
116737 22782
3890 98135
93103 18506
14764 134508
107699 107653
151...

output:

4 7 8 9 10 18 21 22 23 24 25 26 33 34 35 39 42 45 46 47 48 49 50 51 53 55 57 58 59 60 62 66 69 70 72 73 74 75 79 82 84 86 87 92 96 98 99 100 101 102 104 105 106 107 109 110 111 115 118 121 123 125 127 133 134 136 138 139 142 143 144 146 147 157 158 159 162 163 165 166 167 169 170 171 173 176 179 182...

result:

ok ok (1 test case)

Test #46:

score: 0
Accepted
time: 148ms
memory: 46228kb

input:

1
200000 200000
10712 34133
109916 81898
148586 4152
6534 159576
7955 53276
15698 110638
182088 163751
60650 31286
73846 141810
54346 154107
123853 122076
157857 161032
36509 82064
151785 146929
124102 184007
26103 42788
135406 130776
30940 184626
184648 4748
54625 68760
4035 142644
13678 114822
386...

output:

1 2 3 4 5 6 7 9 10 11 12 14 15 17 18 19 21 22 23 24 28 29 31 32 33 34 35 36 37 39 40 42 43 44 46 47 48 49 51 52 53 54 55 56 57 60 62 63 66 68 69 70 71 72 73 74 75 76 78 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 106 109 110 111 113 115 116 118 119 121 122 123 125 126...

result:

ok ok (1 test case)