QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106770#5670. Group GuestsmaspyAC ✓2873ms550292kbC++2333.8kb2023-05-19 05:27:572023-05-19 05:28:02

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-19 05:28:02]
  • 评测
  • 测评结果:AC
  • 用时:2873ms
  • 内存:550292kb
  • [2023-05-19 05:27:57]
  • 提交

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 3 "main.cpp"

#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 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;
    set<int> used;
    Graph<T, directed> G(n);
    FOR(i, n) {
      for (auto&& e: (*this)[V[i]]) {
        if (used.count(e.id)) continue;
        int a = e.frm, b = e.to;
        if (MP.count(a) && MP.count(b)) {
          used.insert(e.id);
          G.add(MP[a], MP[b], 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 2 "library/graph/block_cut.hpp"

/*
block-cut tree を、block に通常の頂点を隣接させて拡張しておく
https://twitter.com/noshi91/status/1529858538650374144?s=20&t=eznpFbuD9BDhfTb4PplFUg
[0, n):もとの頂点 [n, n + n_block):block
関節点:[0, n) のうちで、degree >= 2 を満たすもの

孤立点は、1 点だけからなる block
*/
template <typename GT>
Graph<int, 0> block_cut(GT& G) {
  int n = G.N;
  vc<int> low(n), ord(n), st;
  vc<bool> used(n);
  st.reserve(n);
  int nxt = n;
  int k = 0;
  vc<pair<int, int>> edges;

  auto dfs = [&](auto& dfs, int v, int p) -> void {
    st.eb(v);
    used[v] = 1;
    low[v] = ord[v] = k++;
    int child = 0;
    for (auto&& e: G[v]) {
      if (e.to == p) continue;
      if (!used[e.to]) {
        ++child;
        int s = len(st);
        dfs(dfs, e.to, v);
        chmin(low[v], low[e.to]);
        if ((p == -1 && child > 1) || (p != -1 && low[e.to] >= ord[v])) {
          edges.eb(nxt, v);
          while (len(st) > s) {
            edges.eb(nxt, st.back());
            st.pop_back();
          }
          ++nxt;
        }
      } else {
        chmin(low[v], ord[e.to]);
      }
    }
  };
  FOR(v, n) if (!used[v]) {
    dfs(dfs, v, -1);
    for (auto&& x: st) { edges.eb(nxt, x); }
    ++nxt;
    st.clear();
  }
  Graph<int, 0> BCT(nxt);
  for (auto&& [a, b]: edges) BCT.add(a, b);
  BCT.build();
  return BCT;
}
#line 2 "library/graph/tree.hpp"

#line 4 "library/graph/tree.hpp"

// HLD euler tour をとっていろいろ。
// 木以外、非連結でも dfs 順序や親がとれる。
template <typename GT>
struct Tree {
  using Graph_type = GT;
  GT &G;
  using WT = typename GT::cost_type;
  int N;
  vector<int> LID, RID, head, V, parent, VtoE;
  vc<int> depth;
  vc<WT> depth_weighted;

  Tree(GT &G, int r = 0, bool hld = 1) : G(G) { build(r, hld); }

  void build(int r = 0, bool hld = 1) {
    if (r == -1) return; // build を遅延したいとき
    N = G.N;
    LID.assign(N, -1), RID.assign(N, -1), head.assign(N, r);
    V.assign(N, -1), parent.assign(N, -1), VtoE.assign(N, -1);
    depth.assign(N, -1), depth_weighted.assign(N, 0);
    assert(G.is_prepared());
    int t1 = 0;
    dfs_sz(r, -1, hld);
    dfs_hld(r, t1);
  }

  void dfs_sz(int v, int p, bool hld) {
    auto &sz = RID;
    parent[v] = p;
    depth[v] = (p == -1 ? 0 : depth[p] + 1);
    sz[v] = 1;
    int l = G.indptr[v], r = G.indptr[v + 1];
    auto &csr = G.csr_edges;
    // 使う辺があれば先頭にする
    for (int i = r - 2; i >= l; --i) {
      if (hld && depth[csr[i + 1].to] == -1) swap(csr[i], csr[i + 1]);
    }
    int hld_sz = 0;
    for (int i = l; i < r; ++i) {
      auto e = csr[i];
      if (depth[e.to] != -1) continue;
      depth_weighted[e.to] = depth_weighted[v] + e.cost;
      VtoE[e.to] = e.id;
      dfs_sz(e.to, v, hld);
      sz[v] += sz[e.to];
      if (hld && chmax(hld_sz, sz[e.to]) && l < i) { swap(csr[l], csr[i]); }
    }
  }

  void dfs_hld(int v, int &times) {
    LID[v] = times++;
    RID[v] += LID[v];
    V[LID[v]] = v;
    bool heavy = true;
    for (auto &&e: G[v]) {
      if (depth[e.to] <= depth[v]) continue;
      head[e.to] = (heavy ? head[v] : e.to);
      heavy = false;
      dfs_hld(e.to, times);
    }
  }

  vc<int> heavy_path_at(int v) {
    vc<int> P = {v};
    while (1) {
      int a = P.back();
      for (auto &&e: G[a]) {
        if (e.to != parent[a] && head[e.to] == v) {
          P.eb(e.to);
          break;
        }
      }
      if (P.back() == a) break;
    }
    return P;
  }

  int e_to_v(int eid) {
    auto e = G.edges[eid];
    return (parent[e.frm] == e.to ? e.frm : e.to);
  }
  int v_to_e(int v) { return VtoE[v]; }

  int ELID(int v) { return 2 * LID[v] - depth[v]; }
  int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }

  /* k: 0-indexed */
  int LA(int v, int k) {
    assert(k <= depth[v]);
    while (1) {
      int u = head[v];
      if (LID[v] - k >= LID[u]) return V[LID[v] - k];
      k -= LID[v] - LID[u] + 1;
      v = parent[u];
    }
  }
  int la(int u, int v) { return LA(u, v); }

  int LCA(int u, int v) {
    for (;; v = parent[head[v]]) {
      if (LID[u] > LID[v]) swap(u, v);
      if (head[u] == head[v]) return u;
    }
  }
  // root を根とした場合の lca
  int LCA_root(int u, int v, int root) {
    return LCA(u, v) ^ LCA(u, root) ^ LCA(v, root);
  }
  int lca(int u, int v) { return LCA(u, v); }
  int lca_root(int u, int v, int root) { return LCA_root(u, v, root); }

  int subtree_size(int v, int root = -1) {
    if (root == -1) return RID[v] - LID[v];
    if (v == root) return N;
    int x = jump(v, root, 1);
    if (in_subtree(v, x)) return RID[v] - LID[v];
    return N - RID[x] + LID[x];
  }

  int dist(int a, int b) {
    int c = LCA(a, b);
    return depth[a] + depth[b] - 2 * depth[c];
  }

  WT dist_weighted(int a, int b) {
    int c = LCA(a, b);
    return depth_weighted[a] + depth_weighted[b] - WT(2) * depth_weighted[c];
  }

  // a is in b
  bool in_subtree(int a, int b) { return LID[b] <= LID[a] && LID[a] < RID[b]; }

  int jump(int a, int b, ll k) {
    if (k == 1) {
      if (a == b) return -1;
      return (in_subtree(b, a) ? LA(b, depth[b] - depth[a] - 1) : parent[a]);
    }
    int c = LCA(a, b);
    int d_ac = depth[a] - depth[c];
    int d_bc = depth[b] - depth[c];
    if (k > d_ac + d_bc) return -1;
    if (k <= d_ac) return LA(a, k);
    return LA(b, d_ac + d_bc - k);
  }

  vc<int> collect_child(int v) {
    vc<int> res;
    for (auto &&e: G[v])
      if (e.to != parent[v]) res.eb(e.to);
    return res;
  }

  vc<pair<int, int>> get_path_decomposition(int u, int v, bool edge) {
    // [始点, 終点] の"閉"区間列。
    vc<pair<int, int>> up, down;
    while (1) {
      if (head[u] == head[v]) break;
      if (LID[u] < LID[v]) {
        down.eb(LID[head[v]], LID[v]);
        v = parent[head[v]];
      } else {
        up.eb(LID[u], LID[head[u]]);
        u = parent[head[u]];
      }
    }
    if (LID[u] < LID[v]) down.eb(LID[u] + edge, LID[v]);
    elif (LID[v] + edge <= LID[u]) up.eb(LID[u], LID[v] + edge);
    reverse(all(down));
    up.insert(up.end(), all(down));
    return up;
  }

  vc<int> restore_path(int u, int v) {
    vc<int> P;
    for (auto &&[a, b]: get_path_decomposition(u, v, 0)) {
      if (a <= b) {
        FOR(i, a, b + 1) P.eb(V[i]);
      } else {
        FOR_R(i, b, a + 1) P.eb(V[i]);
      }
    }
    return P;
  }
};
#line 2 "library/enumerate/triangle.hpp"

template <typename Gr, typename F>
void enumerate_triangle(Gr& G, F query) {
  int N = G.N;
  Graph<int, 1> H(N);
  for (auto&& e: G.edges) {
    // 注意:次数比較だけだと DAG にならず、サイクルができてしまう
    if (mp(G.deg(e.frm), e.frm) < mp(G.deg(e.to), e.to))
      H.add(e.frm, e.to);
    else
      H.add(e.to, e.frm);
  }
  H.build();

  vc<bool> table(N);
  FOR(a, N) {
    for (auto&& e: H[a]) { table[e.to] = 1; }
    for (auto&& e: H[a]) {
      int b = e.to;
      for (auto&& f: H[b]) {
        int c = f.to;
        if (table[c]) query(a, b, c);
      }
    }
    for (auto&& e: H[a]) { table[e.to] = 0; }
  }
}
#line 2 "library/ds/unionfind/unionfind.hpp"

struct UnionFind {
  int n, n_comp;
  vc<int> dat; // par or (-size)
  UnionFind(int n = 0) { build(n); }

  void build(int m) {
    n = m, n_comp = m;
    dat.assign(n, -1);
  }

  void reset() { build(n); }

  int operator[](int x) {
    while (dat[x] >= 0) {
      int pp = dat[dat[x]];
      if (pp < 0) { return dat[x]; }
      x = dat[x] = pp;
    }
    return x;
  }

  ll size(int x) {
    assert(dat[x] < 0);
    return -dat[x];
  }

  bool merge(int x, int y) {
    x = (*this)[x], y = (*this)[y];
    if (x == y) return false;
    if (-dat[x] < -dat[y]) swap(x, y);
    dat[x] += dat[y], dat[y] = x, n_comp--;
    return true;
  }
};
#line 2 "library/ds/rollback_array.hpp"

template <typename T>
struct Rollback_Array {
  int N;
  vc<T> dat;
  vc<pair<int, T>> history;

  Rollback_Array(vc<T> x) : N(len(x)), dat(x) {}
  Rollback_Array(int N) : N(N), dat(N) {}
  template <typename F>
  Rollback_Array(int N, F f) : N(N) {
    dat.reserve(N);
    FOR(i, N) dat.eb(f(i));
  }

  int time() { return len(history); }
  void rollback(int t) {
    FOR_R(i, t, time()) {
      auto& [idx, v] = history[i];
      dat[idx] = v;
    }
    history.resize(t);
  }
  T get(int idx) { return dat[idx]; }
  void set(int idx, T x) {
    history.eb(idx, dat[idx]);
    dat[idx] = x;
  }

  vc<T> get_all() {
    vc<T> res(N);
    FOR(i, N) res[i] = get(i);
    return res;
  }
};
#line 2 "library/ds/unionfind/rollback_unionfind.hpp"

struct Rollback_UnionFind {
  Rollback_Array<int> dat; // parent or size

  Rollback_UnionFind(int n) : dat(vc<int>(n, -1)) {}

  int operator[](int v) {
    while (dat.get(v) >= 0) v = dat.get(v);
    return v;
  }

  ll size(int v) { return -dat.get((*this)[v]); }
  int time() { return dat.time(); }
  void rollback(int t) { dat.rollback(t); }

  bool merge(int a, int b) {
    a = (*this)[a], b = (*this)[b];
    if (a == b) return false;
    if (dat.get(a) > dat.get(b)) swap(a, b);
    dat.set(a, dat.get(a) + dat.get(b));
    dat.set(b, a);
    return true;
  }
};
#line 1 "library/ds/offline_query/add_remove_query.hpp"
/*
・時刻 t に x を追加する
・時刻 t に x を削除する
があるときに、
・時刻 [l, r) に x を追加する
に変換する。
クエリが時系列順に来ることが分かっているときは monotone = true の方が高速。
*/
template <typename X, bool monotone>
struct Add_Remove_Query {
  map<X, int> MP;
  vc<tuple<int, int, X>> dat;
  map<X, vc<int>> ADD;
  map<X, vc<int>> RM;

  void add(int time, X x) {
    if (monotone) return add_monotone(time, x);
    ADD[x].eb(time);
  }
  void remove(int time, X x) {
    if (monotone) return remove_monotone(time, x);
    RM[x].eb(time);
  }

  // すべてのクエリが終わった現在時刻を渡す
  vc<tuple<int, int, X>> calc(int time) {
    if (monotone) return calc_monotone(time);
    vc<tuple<int, int, X>> dat;
    for (auto&& [x, A]: ADD) {
      vc<int> B;
      if (RM.count(x)) {
        B = RM[x];
        RM.erase(x);
      }
      if (len(B) < len(A)) B.eb(time);
      assert(len(A) == len(B));

      sort(all(A));
      sort(all(B));
      FOR(i, len(A)) {
        assert(A[i] <= B[i]);
        if (A[i] < B[i]) dat.eb(A[i], B[i], x);
      }
    }
    assert(len(RM) == 0);
    return dat;
  }

private:
  void add_monotone(int time, X x) {
    assert(!MP.count(x));
    MP[x] = time;
  }
  void remove_monotone(int time, X x) {
    auto it = MP.find(x);
    assert(it != MP.end());
    int t = (*it).se;
    MP.erase(it);
    if (t == time) return;
    dat.eb(t, time, x);
  }
  vc<tuple<int, int, X>> calc_monotone(int time) {
    for (auto&& [x, t]: MP) {
      if (t == time) continue;
      dat.eb(t, time, x);
    }
    return dat;
  }
};
#line 12 "main.cpp"

bool triangle(Graph<bool, 0> G) {
  ll N = G.N;
  ll M = G.M;
  // DFS tree
  Graph<bool, 1> DFS(N);
  {
    vc<bool> vis(N);
    auto dfs = [&](auto& dfs, int v, int p) -> void {
      vis[v] = 1;
      for (auto&& e: G[v]) {
        if (e.to == p) continue;
        if (vis[e.to]) continue;
        DFS.add(v, e.to);
        dfs(dfs, e.to, v);
      }
    };
    dfs(dfs, 0, -1);
    DFS.build();
    assert(DFS.M == N - 1);
  }

  Tree<decltype(DFS)> tree(DFS);

  auto in_tree = [&](int a, int b) -> bool {
    return tree.parent[a] == b || tree.parent[b] == a;
  };

  bool OK = 0;
  using T = tuple<int, int, int>;
  vc<T> cand;

  {
    Graph<int, 1> H(N);
    for (auto&& e: G.edges) {
      // 注意:次数比較だけだと DAG にならず、サイクルができてしまう
      if (mp(G.deg(e.frm), e.frm) < mp(G.deg(e.to), e.to))
        H.add(e.frm, e.to);
      else
        H.add(e.to, e.frm);
    }
    H.build();

    vc<bool> table(N);
    FOR(a, N) {
      for (auto&& e: H[a]) { table[e.to] = 1; }
      for (auto&& e: H[a]) {
        int b = e.to;
        for (auto&& f: H[b]) {
          int c = f.to;
          if (table[c]) {
            if (in_tree(a, b) || in_tree(b, c) || in_tree(c, a)) {
              cand.eb(a, b, c);
            } else {
              return 1;
            }
          }
        }
      }
      for (auto&& e: H[a]) { table[e.to] = 0; }
    }
  }

  // それ以外の消し方は、高々 O(M) 通りである。
  assert(len(cand) <= M);

  // あとは、rollback unionfind で頑張る
  Add_Remove_Query<pair<int, int>, true> X;
  int t = 0;
  for (auto&& e: G.edges) {
    int a = e.frm, b = e.to;
    if (a > b) swap(a, b);
    X.add(t, {a, b});
  }
  for (auto&& [a, b, c]: cand) {
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    X.remove(t, {a, b});
    X.remove(t, {a, c});
    X.remove(t, {b, c});
    ++t;
    X.add(t, {a, b});
    X.add(t, {a, c});
    X.add(t, {b, c});
  }

  Rollback_UnionFind uf(N);
  Rollback_Array<int> A(N); // root -> edge
  int odd = 0;

  // rollback_dfs
  auto upd = X.calc(len(cand));
  vc<int> I(len(upd));
  iota(all(I), 0);

  auto dfs = [&](auto& dfs, vc<int>& upd_query_I, int begin, int end) -> void {
    if (OK) return;
    if (begin == end) return;
    // snapshot
    int memo_odd = odd;
    int uf_time = uf.time();
    int A_time = A.time();

    vc<int> IL, IR;
    int mid = (begin + end) / 2;
    for (auto&& i: upd_query_I) {
      auto [a, b, X] = upd[i];
      if (a <= begin && end <= b) {
        // X で表される update query を処理する
        auto [u, v] = X;
        if (uf[u] != uf[v]) {
          int a = uf[u], b = uf[v];
          int xa = A.get(a), xb = A.get(b);
          if (xa % 2 == 1) --odd;
          if (xb % 2 == 1) --odd;
          int x = A.get(a) + A.get(b);
          if (x % 2 == 1) ++odd;
          uf.merge(u, v);
          a = uf[a];
          A.set(a, x);
        }
        u = uf[u];
        int x = A.get(u);
        if (x % 2 == 1) --odd;
        A.set(u, x + 1);
        if (x % 2 == 0) ++odd;
      } else {
        if (a < mid) IL.eb(i);
        if (mid < b) IR.eb(i);
      }
    }
    if (begin + 1 == end) {
      // 求値クエリ
      if (odd == 0) OK = 1;
    } else {
      dfs(dfs, IL, begin, mid);
      dfs(dfs, IR, mid, end);
    }
    // rollback
    odd = memo_odd;
    uf.rollback(uf_time);
    A.rollback(A_time);
  };
  dfs(dfs, I, 0, len(cand));
  return OK;
}

bool star(Graph<bool, 0> G) {
  ll N = G.N;
  ll M = G.M;
  auto BCT = block_cut<decltype(G)>(G);
  Tree<decltype(BCT)> tree(BCT);

  vc<int> dp(BCT.N);
  for (auto&& e: G.edges) {
    int a = e.frm, b = e.to;
    int idx = tree.jump(a, b, 1);
    dp[idx]++;
  }
  FOR_R(i, 1, BCT.N) {
    int v = tree.V[i];
    int p = tree.parent[v];
    dp[p] += dp[v];
  }

  FOR(v, N) {
    vc<int> nbd;
    for (auto&& e: BCT[v]) nbd.eb(e.to);
    sort(all(nbd));
    int n = len(nbd);
    vc<int> cnt(n);
    for (auto&& e: G[v]) {
      int idx = tree.jump(v, e.to, 1);
      idx = LB(nbd, idx);
      cnt[idx]++;
    }
    vc<int> parity(n);
    FOR(i, n) {
      if (nbd[i] != tree.parent[v]) {
        parity[i] = dp[nbd[i]] & 1;
      } else {
        parity[i] = (M - dp[v]) & 1;
      }
    }
    ll k = 0;
    FOR(i, n) {
      if ((parity[i] - cnt[i]) % 2 == 0) {
        k += cnt[i];
      } else {
        k += cnt[i] - 1;
      }
    }
    if (k >= 3) return true;
  }
  return false;
}

pi solve_connected(Graph<bool, 0> G) {
  ll N = G.N;
  ll M = G.M;
  if (M % 2 == 0) return {0, 0};

  if (triangle(G)) return {0, 0};
  if (star(G)) return {0, 1};
  return {1, 0};
}

void solve() {
  LL(M, N);
  Graph<bool, 0> G(N);
  G.read_graph(M);

  UnionFind uf(N);
  for (auto&& e: G.edges) uf.merge(e.frm, e.to);

  vvc<int> comp(N);
  FOR(v, N) comp[uf[v]].eb(v);

  pi ANS = {0, 0};

  for (auto&& V: comp) {
    if (len(V) <= 1) continue;
    auto H = G.rearrange(V);
    auto [a, b] = solve_connected(H);
    ANS.fi += a, ANS.se += b;
  }
  print(ANS);
}

signed main() {
  solve();
  return 0;
}

详细

Test #1:

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

input:

2 4
1 2
3 4

output:

2 0

result:

ok single line: '2 0'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

2 3
1 2
3 1

output:

0 0

result:

ok single line: '0 0'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3592kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #4:

score: 0
Accepted
time: 751ms
memory: 76620kb

input:

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

output:

383 523

result:

ok single line: '383 523'

Test #5:

score: 0
Accepted
time: 740ms
memory: 76560kb

input:

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

output:

349 522

result:

ok single line: '349 522'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

4 4
1 2
2 4
2 3
3 4

output:

0 0

result:

ok single line: '0 0'

Test #7:

score: 0
Accepted
time: 728ms
memory: 75196kb

input:

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

output:

375 322

result:

ok single line: '375 322'

Test #8:

score: 0
Accepted
time: 716ms
memory: 75188kb

input:

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

output:

366 307

result:

ok single line: '366 307'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3560kb

input:

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

output:

0 1

result:

ok single line: '0 1'

Test #10:

score: 0
Accepted
time: 744ms
memory: 77308kb

input:

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

output:

1032 1376

result:

ok single line: '1032 1376'

Test #11:

score: 0
Accepted
time: 740ms
memory: 77312kb

input:

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

output:

990 1439

result:

ok single line: '990 1439'

Test #12:

score: 0
Accepted
time: 2ms
memory: 3440kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #14:

score: 0
Accepted
time: 2ms
memory: 3440kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

12 8
1 2
1 3
2 3
3 4
3 5
4 5
6 5
6 7
5 7
2 7
7 8
2 8

output:

0 0

result:

ok single line: '0 0'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3440kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #17:

score: 0
Accepted
time: 2ms
memory: 3476kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #18:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

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

output:

0 1

result:

ok single line: '0 1'

Test #19:

score: 0
Accepted
time: 2ms
memory: 3516kb

input:

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

output:

0 1

result:

ok single line: '0 1'

Test #20:

score: 0
Accepted
time: 2ms
memory: 3500kb

input:

4 4
1 3
1 4
2 4
2 3

output:

0 0

result:

ok single line: '0 0'

Test #21:

score: 0
Accepted
time: 2ms
memory: 3540kb

input:

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

output:

1 0

result:

ok single line: '1 0'

Test #22:

score: 0
Accepted
time: 1ms
memory: 3444kb

input:

9 12
1 2
1 3
4 5
5 6
7 9
8 9
10 11
10 12
11 12

output:

0 0

result:

ok single line: '0 0'

Test #23:

score: 0
Accepted
time: 2ms
memory: 3464kb

input:

186 228
1 2
1 3
5 6
5 8
9 11
9 12
13 14
13 15
13 16
17 18
18 19
21 23
22 23
25 26
25 27
26 27
29 32
30 31
33 34
33 36
34 35
37 39
37 40
38 39
41 42
41 43
41 44
42 43
45 46
46 48
49 51
50 52
53 54
53 55
54 56
57 60
58 60
61 62
61 64
62 64
65 67
65 68
66 68
69 70
69 71
69 72
70 72
74 75
74 76
77 78
78...

output:

18 4

result:

ok single line: '18 4'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3436kb

input:

3 4
1 2
3 4
3 2

output:

1 0

result:

ok single line: '1 0'

Test #25:

score: 0
Accepted
time: 5ms
memory: 3728kb

input:

5110 5065
1 2
1 3
6 7
6 9
11 13
11 14
16 17
16 18
16 19
21 22
21 25
26 28
26 30
31 32
31 33
31 35
36 39
36 40
41 42
41 44
41 45
46 48
46 49
46 50
51 52
51 53
51 54
51 55
56 57
57 58
61 63
62 63
66 67
66 68
67 68
71 74
72 73
76 77
76 79
77 78
81 83
81 84
82 83
86 87
86 88
86 89
87 88
91 95
92 93
96 9...

output:

142 140

result:

ok single line: '142 140'

Test #26:

score: 0
Accepted
time: 2ms
memory: 3512kb

input:

3 4
1 2
2 3
2 4

output:

0 1

result:

ok single line: '0 1'

Test #27:

score: 0
Accepted
time: 130ms
memory: 22600kb

input:

245745 196512
1 2
1 3
7 8
7 10
13 15
13 16
19 20
19 21
19 22
25 26
25 29
31 33
31 35
37 38
37 39
37 41
43 46
43 47
49 50
49 52
49 53
55 57
55 58
55 59
61 62
61 63
61 64
61 65
67 68
67 72
73 75
73 78
79 80
79 81
79 84
85 88
85 90
91 92
91 94
91 96
97 99
97 100
97 102
103 104
103 105
103 106
103 108
1...

output:

2097 2626

result:

ok single line: '2097 2626'

Test #28:

score: 0
Accepted
time: 2ms
memory: 3516kb

input:

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

output:

0 1

result:

ok single line: '0 1'

Test #29:

score: 0
Accepted
time: 499ms
memory: 83476kb

input:

999999 841330
1 2
1 3
8 9
8 11
15 17
15 18
22 23
22 24
22 25
29 30
29 33
36 38
36 40
43 44
43 45
43 47
50 53
50 54
57 58
57 60
57 61
64 66
64 67
64 68
71 72
71 73
71 74
71 75
78 79
78 83
85 87
85 90
92 93
92 94
92 97
99 102
99 104
106 107
106 109
106 111
113 115
113 116
113 118
120 121
120 122
120 1...

output:

7646 12754

result:

ok single line: '7646 12754'

Test #30:

score: 0
Accepted
time: 494ms
memory: 79468kb

input:

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

output:

3532 7627

result:

ok single line: '3532 7627'

Test #31:

score: 0
Accepted
time: 491ms
memory: 78920kb

input:

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

output:

3201 7345

result:

ok single line: '3201 7345'

Test #32:

score: 0
Accepted
time: 457ms
memory: 77252kb

input:

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

output:

2402 4121

result:

ok single line: '2402 4121'

Test #33:

score: 0
Accepted
time: 438ms
memory: 74616kb

input:

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

output:

943 2394

result:

ok single line: '943 2394'

Test #34:

score: 0
Accepted
time: 480ms
memory: 79252kb

input:

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

output:

3698 7209

result:

ok single line: '3698 7209'

Test #35:

score: 0
Accepted
time: 439ms
memory: 76556kb

input:

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

output:

1310 3756

result:

ok single line: '1310 3756'

Test #36:

score: 0
Accepted
time: 433ms
memory: 75776kb

input:

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

output:

835 3556

result:

ok single line: '835 3556'

Test #37:

score: 0
Accepted
time: 439ms
memory: 74352kb

input:

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

output:

331 2414

result:

ok single line: '331 2414'

Test #38:

score: 0
Accepted
time: 425ms
memory: 74176kb

input:

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

output:

164 2050

result:

ok single line: '164 2050'

Test #39:

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

input:

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

output:

3578 4667

result:

ok single line: '3578 4667'

Test #40:

score: 0
Accepted
time: 454ms
memory: 77668kb

input:

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

output:

1590 5625

result:

ok single line: '1590 5625'

Test #41:

score: 0
Accepted
time: 431ms
memory: 75224kb

input:

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

output:

653 1686

result:

ok single line: '653 1686'

Test #42:

score: 0
Accepted
time: 445ms
memory: 76340kb

input:

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

output:

944 4865

result:

ok single line: '944 4865'

Test #43:

score: 0
Accepted
time: 444ms
memory: 74232kb

input:

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

output:

256 2136

result:

ok single line: '256 2136'

Test #44:

score: 0
Accepted
time: 366ms
memory: 72612kb

input:

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

output:

223 715

result:

ok single line: '223 715'

Test #45:

score: 0
Accepted
time: 450ms
memory: 76200kb

input:

999990 686567
1 3
1 4
1 5
1 6
2 5
2 7
5 7
6 7
8 9
8 10
8 11
8 12
8 13
9 12
9 14
12 14
13 14
15 21
16 19
16 21
19 21
20 21
22 23
22 28
23 26
23 28
26 28
27 28
29 31
29 35
30 33
30 35
33 35
34 35
36 37
36 38
36 42
37 40
37 42
40 42
41 42
43 46
43 49
44 47
44 49
47 49
48 49
50 51
50 53
50 56
51 54
51 5...

output:

931 4522

result:

ok single line: '931 4522'

Test #46:

score: 0
Accepted
time: 389ms
memory: 74140kb

input:

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

output:

151 2420

result:

ok single line: '151 2420'

Test #47:

score: 0
Accepted
time: 369ms
memory: 72760kb

input:

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

output:

396 361

result:

ok single line: '396 361'

Test #48:

score: 0
Accepted
time: 377ms
memory: 73708kb

input:

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

output:

277 414

result:

ok single line: '277 414'

Test #49:

score: 0
Accepted
time: 347ms
memory: 72384kb

input:

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

output:

104 179

result:

ok single line: '104 179'

Test #50:

score: 0
Accepted
time: 315ms
memory: 70388kb

input:

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

output:

102 6

result:

ok single line: '102 6'

Test #51:

score: 0
Accepted
time: 2ms
memory: 4356kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #52:

score: 0
Accepted
time: 2ms
memory: 3472kb

input:

4 5
1 2
2 3
3 4
4 5

output:

0 0

result:

ok single line: '0 0'

Test #53:

score: 0
Accepted
time: 426ms
memory: 72848kb

input:

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

output:

38 1247

result:

ok single line: '38 1247'

Test #54:

score: 0
Accepted
time: 347ms
memory: 69156kb

input:

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

output:

8 0

result:

ok single line: '8 0'

Test #55:

score: 0
Accepted
time: 280ms
memory: 68324kb

input:

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

output:

7 0

result:

ok single line: '7 0'

Test #56:

score: 0
Accepted
time: 379ms
memory: 72592kb

input:

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

output:

10 374

result:

ok single line: '10 374'

Test #57:

score: 0
Accepted
time: 409ms
memory: 73348kb

input:

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

output:

656 1809

result:

ok single line: '656 1809'

Test #58:

score: 0
Accepted
time: 2ms
memory: 3472kb

input:

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

output:

1 0

result:

ok single line: '1 0'

Test #59:

score: 0
Accepted
time: 216ms
memory: 75668kb

input:

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

output:

123 0

result:

ok single line: '123 0'

Test #60:

score: 0
Accepted
time: 709ms
memory: 74164kb

input:

999990 599994
1 3
1 4
1 6
1 7
1 8
1 9
3 4
3 6
4 7
5 7
5 8
5 9
7 8
7 9
8 9
10 11
10 13
10 18
11 12
11 15
11 18
12 17
13 14
13 15
13 18
14 15
14 18
15 16
15 18
16 17
19 20
19 23
19 25
19 26
20 21
20 23
21 27
22 23
22 24
22 25
22 26
22 27
23 25
23 26
24 26
28 29
28 32
28 33
28 36
29 34
29 35
29 36
30 3...

output:

57 40

result:

ok single line: '57 40'

Test #61:

score: 0
Accepted
time: 0ms
memory: 3444kb

input:

8 9
9 8
6 7
3 2
5 4
1 2
4 3
6 5
7 8

output:

0 0

result:

ok single line: '0 0'

Test #62:

score: 0
Accepted
time: 2804ms
memory: 226032kb

input:

999999 1000000
1 560136
2 102142
2 236736
3 309371
3 491463
4 538764
5 470246
6 278170
7 227277
8 673767
9 37182
9 231457
11 414293
11 583390
11 812999
11 868721
11 925233
12 254802
12 517049
12 530488
12 910757
12 943612
13 901211
14 1496
14 802703
15 684146
18 159626
18 209532
18 394262
18 583396
...

output:

20012 719

result:

ok single line: '20012 719'

Test #63:

score: 0
Accepted
time: 1068ms
memory: 222256kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #64:

score: 0
Accepted
time: 2173ms
memory: 488860kb

input:

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

output:

1 0

result:

ok single line: '1 0'

Test #65:

score: 0
Accepted
time: 2873ms
memory: 536288kb

input:

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

output:

0 1

result:

ok single line: '0 1'

Test #66:

score: 0
Accepted
time: 2736ms
memory: 536300kb

input:

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

output:

0 0

result:

ok single line: '0 0'

Test #67:

score: 0
Accepted
time: 2277ms
memory: 550292kb

input:

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

output:

1 0

result:

ok single line: '1 0'

Test #68:

score: 0
Accepted
time: 746ms
memory: 88936kb

input:

999915 952300
1 41
1 47
1 72
2 16
2 88
2 95
3 9
3 26
3 91
4 21
4 37
4 85
5 14
5 49
5 88
6 25
7 71
7 74
7 84
8 22
9 34
9 83
10 16
10 90
11 18
12 35
12 52
14 17
14 44
14 72
15 26
15 80
15 83
16 42
17 65
18 29
18 85
19 41
19 74
21 38
22 25
22 37
22 53
23 38
24 39
24 63
24 98
25 64
25 91
26 44
26 55
26 ...

output:

15511 1803

result:

ok single line: '15511 1803'

Test #69:

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

input:

999975 995000
1 359
1 729
1 966
2 263
2 487
4 372
4 391
4 877
5 883
6 248
6 254
6 703
7 141
7 333
8 496
8 602
8 934
9 747
10 283
11 386
11 815
12 954
13 963
14 437
14 891
15 274
15 826
16 56
16 278
16 893
18 247
18 789
18 826
19 409
19 695
20 158
20 624
20 838
20 993
21 289
21 734
22 936
22 938
23 2...

output:

19402 813

result:

ok single line: '19402 813'

Test #70:

score: 0
Accepted
time: 908ms
memory: 92836kb

input:

990495 990000
1 4654
2 553
2 4245
3 2524
3 3264
3 4715
3 5674
3 8204
4 5011
5 2857
5 9071
6 1514
6 5066
6 6536
6 7994
7 827
7 6412
8 7290
9 871
9 1936
9 2124
9 6867
11 8860
12 1347
12 3879
12 8952
13 1635
13 3529
14 3313
14 7551
14 8286
15 307
15 614
15 6202
15 7888
15 7935
16 2070
17 689
18 2352
18...

output:

19786 687

result:

ok single line: '19786 687'

Test #71:

score: 0
Accepted
time: 771ms
memory: 86600kb

input:

999955 909050
1 4
1 13
1 28
1 33
1 36
2 25
3 42
4 16
5 25
7 22
7 24
7 30
7 33
7 40
7 50
8 19
8 27
9 17
9 24
10 19
10 20
10 24
10 37
12 34
13 32
13 36
14 36
15 24
16 20
16 31
17 22
18 24
19 32
19 37
19 43
20 27
20 44
21 27
21 33
24 31
24 36
24 41
25 26
26 44
27 28
27 39
27 40
28 36
28 49
30 37
30 39
...

output:

11763 2903

result:

ok single line: '11763 2903'

Test #72:

score: 0
Accepted
time: 754ms
memory: 89936kb

input:

999900 990000
1 33
1 290
1 323
1 327
1 341
2 12
2 17
2 46
2 198
3 204
3 256
4 27
4 313
6 236
7 217
9 153
9 431
10 21
10 415
10 419
11 58
12 55
12 128
14 390
15 34
16 240
16 321
17 262
18 231
18 238
19 78
19 130
19 266
19 271
20 203
20 474
20 494
21 25
21 429
22 348
22 484
23 388
23 463
24 209
24 243...

output:

19065 967

result:

ok single line: '19065 967'

Test #73:

score: 0
Accepted
time: 849ms
memory: 91332kb

input:

995995 995000
1 516
1 2254
1 3620
2 3500
3 184
3 917
3 1224
3 3467
3 4653
4 537
5 3604
6 687
6 1559
6 4129
7 462
7 1012
7 2094
7 2665
7 4363
7 4473
8 300
8 307
8 1678
8 2921
8 4070
9 3102
9 4561
11 1749
11 3944
11 4927
12 1479
12 3635
13 492
14 1693
14 2362
14 4867
15 2073
15 2166
15 2186
16 1523
16...

output:

19765 706

result:

ok single line: '19765 706'

Test #74:

score: 0
Accepted
time: 1399ms
memory: 366692kb

input:

999905 196061
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 20
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
3 19
3 20
4 11
4 12
4 13
4 14
4 15
4 16
4 17
4 18
4 19
4 20
5 11
5 12
5 13
5 14
5 15
5 16
5 17
5 18
5 19
5 20
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6...

output:

0 1

result:

ok single line: '0 1'

Test #75:

score: 0
Accepted
time: 1373ms
memory: 366612kb

input:

999905 196061
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 20
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
3 19
3 20
4 11
4 12
4 13
4 14
4 15
4 16
4 17
4 18
4 19
4 20
5 11
5 12
5 13
5 14
5 15
5 16
5 17
5 18
5 19
5 20
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6...

output:

0 0

result:

ok single line: '0 0'

Test #76:

score: 0
Accepted
time: 2075ms
memory: 361464kb

input:

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

output:

1 0

result:

ok single line: '1 0'