QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639893#7860. Graph of Maximum Degree 3maspyAC ✓221ms53416kbC++2027.9kb2024-10-13 23:32:082024-10-13 23:32:08

Judging History

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

  • [2024-10-13 23:32:08]
  • 评测
  • 测评结果:AC
  • 用时:221ms
  • 内存:53416kb
  • [2024-10-13 23:32:08]
  • 提交

answer

#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else

// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
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); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(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>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

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

#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) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  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;
    (check(x) ? ok : ng) = 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;
    (check(x) ? ok : ng) = 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;
}

template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
  vc<T> &res = first;
  (res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/library/other/io.hpp"
#define FASTIO
#include <unistd.h>

// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[10000][4];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i][j] = n % 10 | '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
  if (pir < SZ) ibuf[pir++] = '\n';
}

inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

void rd(char &c) {
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
}

void rd(string &x) {
  x.clear();
  char c;
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
  do {
    x += c;
    if (pil == pir) load();
    c = ibuf[pil++];
  } while (!isspace(c));
}

template <typename T>
void rd_real(T &x) {
  string s;
  rd(s);
  x = stod(s);
}

template <typename T>
void rd_integer(T &x) {
  if (pil + 100 > pir) load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (c == '-') { minus = 1, c = ibuf[pil++]; }
  }
  x = 0;
  while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (minus) x = -x;
  }
}

void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }

template <class T, class U>
void rd(pair<T, U> &p) {
  return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto &x = std::get<N>(t);
    rd(x);
    rd_tuple<N + 1>(t);
  }
}
template <class... T>
void rd(tuple<T...> &tpl) {
  rd_tuple(tpl);
}

template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
  for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
  for (auto &d: x) rd(d);
}

void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
  rd(h), read(t...);
}

void wt(const char c) {
  if (por == SZ) flush();
  obuf[por++] = c;
}
void wt(const string s) {
  for (char c: s) wt(c);
}
void wt(const char *s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; i++) wt(s[i]);
}

template <typename T>
void wt_integer(T x) {
  if (por > SZ - 100) flush();
  if (x < 0) { obuf[por++] = '-', x = -x; }
  int outi;
  for (outi = 96; x >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[x % 10000], 4);
    x /= 10000;
  }
  if (x >= 1000) {
    memcpy(obuf + por, pre.num[x], 4);
    por += 4;
  } else if (x >= 100) {
    memcpy(obuf + por, pre.num[x] + 1, 3);
    por += 3;
  } else if (x >= 10) {
    int q = (x * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (x - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = x | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt_real(T x) {
  ostringstream oss;
  oss << fixed << setprecision(15) << double(x);
  string s = oss.str();
  wt(s);
}

void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first);
  wt(' ');
  wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;

#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define U32(...)   \
  u32 __VA_ARGS__; \
  read(__VA_ARGS__)
#define U64(...)   \
  u64 __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 "/home/maspy/compro/library/mod/modint_common.hpp"

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

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

template <typename mint>
mint inv(int n) {
  static const int mod = mint::get_mod();
  static vector<mint> dat = {0, 1};
  assert(0 <= n);
  if (n >= mod) n %= mod;
  while (len(dat) <= n) {
    int k = len(dat);
    int q = (mod + k - 1) / k;
    dat.eb(dat[k * q - mod] * mint::raw(q));
  }
  return dat[n];
}

template <typename mint>
mint fact(int n) {
  static const int mod = mint::get_mod();
  assert(0 <= n && n < mod);
  static vector<mint> dat = {1, 1};
  while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * mint::raw(len(dat)));
  return dat[n];
}

template <typename mint>
mint fact_inv(int n) {
  static vector<mint> dat = {1, 1};
  if (n < 0) return mint(0);
  while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * inv<mint>(len(dat)));
  return dat[n];
}

template <class mint, class... Ts>
mint fact_invs(Ts... xs) {
  return (mint(1) * ... * fact_inv<mint>(xs));
}

template <typename mint, class Head, class... Tail>
mint multinomial(Head &&head, Tail &&... tail) {
  return fact<mint>(head) * fact_invs<mint>(std::forward<Tail>(tail)...);
}

template <typename mint>
mint C_dense(int n, int k) {
  static vvc<mint> C;
  static int H = 0, W = 0;
  auto calc = [&](int i, int j) -> mint {
    if (i == 0) return (j == 0 ? mint(1) : mint(0));
    return C[i - 1][j] + (j ? C[i - 1][j - 1] : 0);
  };
  if (W <= k) {
    FOR(i, H) {
      C[i].resize(k + 1);
      FOR(j, W, k + 1) { C[i][j] = calc(i, j); }
    }
    W = k + 1;
  }
  if (H <= n) {
    C.resize(n + 1);
    FOR(i, H, n + 1) {
      C[i].resize(W);
      FOR(j, W) { C[i][j] = calc(i, j); }
    }
    H = n + 1;
  }
  return C[n][k];
}

template <typename mint, bool large = false, bool dense = false>
mint C(ll n, ll k) {
  assert(n >= 0);
  if (k < 0 || n < k) return 0;
  if constexpr (dense) return C_dense<mint>(n, k);
  if constexpr (!large) return multinomial<mint>(n, k, n - k);
  k = min(k, n - k);
  mint x(1);
  FOR(i, k) x *= mint(n - i);
  return x * fact_inv<mint>(k);
}

template <typename mint, bool large = false>
mint C_inv(ll n, ll k) {
  assert(n >= 0);
  assert(0 <= k && k <= n);
  if (!large) return fact_inv<mint>(n) * fact<mint>(k) * fact<mint>(n - k);
  return mint(1) / C<mint, 1>(n, k);
}

// [x^d](1-x)^{-n}
template <typename mint, bool large = false, bool dense = false>
mint C_negative(ll n, ll d) {
  assert(n >= 0);
  if (d < 0) return mint(0);
  if (n == 0) { return (d == 0 ? mint(1) : mint(0)); }
  return C<mint, large, dense>(n + d - 1, d);
}
#line 3 "/home/maspy/compro/library/mod/modint.hpp"

template <int mod>
struct modint {
  static constexpr u32 umod = u32(mod);
  static_assert(umod < u32(1) << 31);
  u32 val;

  static modint raw(u32 v) {
    modint x;
    x.val = v;
    return x;
  }
  constexpr modint() : val(0) {}
  constexpr modint(u32 x) : val(x % umod) {}
  constexpr modint(u64 x) : val(x % umod) {}
  constexpr modint(u128 x) : val(x % umod) {}
  constexpr modint(int x) : val((x %= mod) < 0 ? x + mod : x){};
  constexpr modint(ll x) : val((x %= mod) < 0 ? x + mod : x){};
  constexpr modint(i128 x) : val((x %= mod) < 0 ? x + mod : x){};
  bool operator<(const modint &other) const { return val < other.val; }
  modint &operator+=(const modint &p) {
    if ((val += p.val) >= umod) val -= umod;
    return *this;
  }
  modint &operator-=(const modint &p) {
    if ((val += umod - p.val) >= umod) val -= umod;
    return *this;
  }
  modint &operator*=(const modint &p) {
    val = u64(val) * p.val % umod;
    return *this;
  }
  modint &operator/=(const modint &p) {
    *this *= p.inverse();
    return *this;
  }
  modint operator-() const { return modint::raw(val ? mod - val : u32(0)); }
  modint operator+(const modint &p) const { return modint(*this) += p; }
  modint operator-(const modint &p) const { return modint(*this) -= p; }
  modint operator*(const modint &p) const { return modint(*this) *= p; }
  modint operator/(const modint &p) const { return modint(*this) /= p; }
  bool operator==(const modint &p) const { return val == p.val; }
  bool operator!=(const modint &p) const { return val != p.val; }
  modint inverse() const {
    int a = val, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b), swap(u -= t * v, v);
    }
    return modint(u);
  }
  modint pow(ll n) const {
    assert(n >= 0);
    modint ret(1), mul(val);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  static constexpr int get_mod() { return mod; }
  // (n, r), r は 1 の 2^n 乗根
  static constexpr pair<int, int> ntt_info() {
    if (mod == 120586241) return {20, 74066978};
    if (mod == 167772161) return {25, 17};
    if (mod == 469762049) return {26, 30};
    if (mod == 754974721) return {24, 362};
    if (mod == 880803841) return {23, 211};
    if (mod == 943718401) return {22, 663003469};
    if (mod == 998244353) return {23, 31};
    if (mod == 1004535809) return {21, 836905998};
    if (mod == 1045430273) return {20, 363};
    if (mod == 1051721729) return {20, 330};
    if (mod == 1053818881) return {20, 2789};
    return {-1, -1};
  }
  static constexpr bool can_ntt() { return ntt_info().fi != -1; }
};

#ifdef FASTIO
template <int mod>
void rd(modint<mod> &x) {
  fastio::rd(x.val);
  x.val %= mod;
  // assert(0 <= x.val && x.val < mod);
}
template <int mod>
void wt(modint<mod> x) {
  fastio::wt(x.val);
}
#endif

using modint107 = modint<1000000007>;
using modint998 = modint<998244353>;
#line 2 "/home/maspy/compro/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) {
    x = (*this)[x];
    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;
  }

  vc<int> get_all() {
    vc<int> A(n);
    FOR(i, n) A[i] = (*this)[i];
    return A;
  }
};
#line 2 "/home/maspy/compro/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 {
  static constexpr bool is_directed = directed;
  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; }

  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;
  }

#ifdef FASTIO
  // 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();
  }
#endif

  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];
  }

#ifdef FASTIO
  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);
    }
  }
#endif

  vc<int> new_idx;
  vc<bool> used_e;

  // G における頂点 V[i] が、新しいグラフで i になるようにする
  // {G, es}
  // sum(deg(v)) の計算量になっていて、
  // 新しいグラフの n+m より大きい可能性があるので注意
  Graph<T, directed> rearrange(vc<int> V, bool keep_eid = 0) {
    if (len(new_idx) != N) new_idx.assign(N, -1);
    int n = len(V);
    FOR(i, n) new_idx[V[i]] = i;
    Graph<T, directed> G(n);
    vc<int> history;
    FOR(i, n) {
      for (auto&& e: (*this)[V[i]]) {
        if (len(used_e) <= e.id) used_e.resize(e.id + 1);
        if (used_e[e.id]) continue;
        int a = e.frm, b = e.to;
        if (new_idx[a] != -1 && new_idx[b] != -1) {
          history.eb(e.id);
          used_e[e.id] = 1;
          int eid = (keep_eid ? e.id : -1);
          G.add(new_idx[a], new_idx[b], e.cost, eid);
        }
      }
    }
    FOR(i, n) new_idx[V[i]] = -1;
    for (auto&& eid: history) used_e[eid] = 0;
    G.build();
    return G;
  }

  Graph<T, true> to_directed_tree(int root = -1) {
    if (root == -1) root = 0;
    assert(!is_directed && prepared && M == N - 1);
    Graph<T, true> G1(N);
    vc<int> par(N, -1);
    auto dfs = [&](auto& dfs, int v) -> void {
      for (auto& e: (*this)[v]) {
        if (e.to == par[v]) continue;
        par[e.to] = v, dfs(dfs, e.to);
      }
    };
    dfs(dfs, root);
    for (auto& e: edges) {
      int a = e.frm, b = e.to;
      if (par[a] == b) swap(a, b);
      assert(par[b] == a);
      G1.add(a, b, e.cost);
    }
    G1.build();
    return G1;
  }

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 "/home/maspy/compro/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);
  set<pair<int, int>> done;
  auto add = [&](int a, int b) -> void {
    pair<int, int> p = {a, b};
    if (done.count(p)) return;
    done.insert(p);
    H.add(a, b);
  };
  for (auto&& e: G.edges) {
    // 注意:次数比較だけだと DAG にならず、サイクルができてしまう
    if (mp(G.deg(e.frm), e.frm) < mp(G.deg(e.to), e.to))
      add(e.frm, e.to);
    else
      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 7 "main.cpp"

using mint = modint998;

mint solve_connected(Graph<int, 0> G) {
  ll N = G.N;
  mint ANS = 0;
  if (N <= 4) {
    FOR(s, 1, 1 << N) {
      vc<int> V;
      FOR(i, N) if (s >> i & 1) V.eb(i);
      Graph<int, 0> H = G.rearrange(V);
      int n = H.N;
      UnionFind uf1(n), uf2(n);
      for (auto& e: H.edges) {
        if (e.cost == 0) uf1.merge(e.frm, e.to);
        if (e.cost == 1) uf2.merge(e.frm, e.to);
      }
      if (uf1.n_comp == 1 && uf2.n_comp == 1) ANS += 1;
    }
    return ANS;
  }
  // 1 点
  ANS += N;
  // 2 点
  map<pair<int, int>, int> MP;
  for (auto& e: G.edges) {
    int a = e.frm, b = e.to;
    if (a > b) swap(a, b);
    pair<int, int> p = {a, b};
    MP[p] |= 1 << e.cost;
  }
  for (auto& [a, b]: MP)
    if (b == 3) ANS += 1;
  auto get = [&](int x, int y) -> int {
    if (x > y) swap(x, y);
    pair<int, int> p = {x, y};
    return MP[p];
  };

  // 4 点以上はない
  // 3 点
  FOR(v, N) {
    vc<int> nbd;
    for (auto& e: G[v]) nbd.eb(e.to);
    UNIQUE(nbd);
    FOR(j, len(nbd)) FOR(i, j) {
      int x = nbd[i], y = nbd[j];
      int vx = get(v, x);
      int vy = get(v, y);
      int xy = get(x, y);
      if (xy != 0 && v > min(x, y)) continue;
      UnionFind uf1(3), uf2(3);
      if (vx & 1) uf1.merge(0, 1);
      if (vy & 1) uf1.merge(0, 2);
      if (xy & 1) uf1.merge(1, 2);
      if (vx & 2) uf2.merge(0, 1);
      if (vy & 2) uf2.merge(0, 2);
      if (xy & 2) uf2.merge(1, 2);
      if (uf1.n_comp == 1 && uf2.n_comp == 1) ANS += 1;
    }
  }
  return ANS;
}

void solve() {
  LL(N, M);
  Graph<int, 0> G(N);
  G.read_graph(M, 1);
  UnionFind uf(N);
  for (auto& e: G.edges) uf.merge(e.frm, e.to);
  vvc<int> vs(N);
  FOR(v, N) vs[uf[v]].eb(v);
  mint ANS = 0;
  for (auto& V: vs) {
    if (V.empty()) continue;
    Graph<int, 0> H = G.rearrange(V);
    ANS += solve_connected(H);
  }
  print(ANS);
}

signed main() { solve(); }

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 4
1 2 0
1 3 1
2 3 0
2 3 1

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

4 6
1 2 0
2 3 0
3 4 0
1 4 1
2 4 1
1 3 1

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

20 28
9 6 1
9 6 0
3 8 0
8 4 0
3 8 1
3 4 1
2 13 0
13 1 0
19 1 0
2 1 1
2 19 1
13 19 1
14 15 1
14 15 0
7 12 0
12 17 0
20 17 0
7 17 1
7 20 1
12 20 1
16 18 0
18 10 0
5 10 0
16 10 1
16 5 1
18 5 1
4 6 0
9 11 0

output:

27

result:

ok 1 number(s): "27"

Test #4:

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

input:

100 150
93 23 0
23 81 0
76 81 0
93 81 1
93 76 1
23 76 1
100 65 0
65 56 0
19 56 0
100 56 1
100 19 1
65 19 1
2 98 0
2 98 1
26 63 0
63 90 0
26 63 1
26 90 1
6 11 0
11 67 0
6 11 1
6 67 1
37 89 0
89 64 0
25 64 0
37 64 1
37 25 1
89 25 1
84 10 0
10 29 0
75 29 0
84 29 1
84 75 1
10 75 1
7 70 1
7 70 0
28 92 0
...

output:

141

result:

ok 1 number(s): "141"

Test #5:

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

input:

100000 133680
36843 86625 0
86625 63051 0
35524 63051 0
36843 63051 1
36843 35524 1
86625 35524 1
55797 82715 0
55797 82715 1
70147 35104 0
35104 91732 0
70147 35104 1
70147 91732 1
94917 70395 0
70395 68250 0
24100 68250 0
94917 68250 1
94917 24100 1
70395 24100 1
83033 18450 1
83033 18450 0
34462 ...

output:

144604

result:

ok 1 number(s): "144604"

Test #6:

score: 0
Accepted
time: 97ms
memory: 15348kb

input:

100000 133388
86620 74346 0
74346 19047 0
54911 19047 0
86620 19047 1
86620 54911 1
74346 54911 1
23715 93094 0
93094 91208 0
63189 91208 0
23715 91208 1
23715 63189 1
93094 63189 1
99337 41426 1
99337 41426 0
83742 45546 0
45546 73862 0
83742 45546 1
83742 73862 1
85256 2812 0
2812 59368 0
85918 59...

output:

144348

result:

ok 1 number(s): "144348"

Test #7:

score: 0
Accepted
time: 86ms
memory: 14916kb

input:

100000 150000
86541 24385 0
24385 75745 0
52353 75745 0
86541 75745 1
86541 52353 1
24385 52353 1
89075 78015 0
89075 78015 1
52519 74846 0
74846 12045 0
73265 12045 0
52519 12045 1
52519 73265 1
74846 73265 1
17884 63159 0
63159 47308 0
56073 47308 0
17884 47308 1
17884 56073 1
63159 56073 1
72134 ...

output:

144639

result:

ok 1 number(s): "144639"

Test #8:

score: 0
Accepted
time: 84ms
memory: 15496kb

input:

100000 150000
91951 68612 1
91951 68612 0
18361 92673 0
92673 52678 0
86520 52678 0
18361 52678 1
18361 86520 1
92673 86520 1
58779 2421 0
58779 2421 1
66622 6461 0
6461 96943 0
66622 6461 1
66622 96943 1
27201 480 1
27201 480 0
19082 3895 0
3895 17796 0
3117 17796 0
19082 17796 1
19082 3117 1
3895 ...

output:

144471

result:

ok 1 number(s): "144471"

Test #9:

score: 0
Accepted
time: 77ms
memory: 15620kb

input:

100000 150000
43756 3552 0
3552 90269 0
43756 3552 1
43756 90269 1
11104 36935 1
11104 36935 0
11648 5480 0
5480 45320 0
11648 5480 1
11648 45320 1
19216 85746 0
19216 85746 1
68825 11173 0
11173 43155 0
68825 11173 1
68825 43155 1
27349 75259 0
27349 75259 1
1704 24478 0
24478 5980 0
1704 24478 1
1...

output:

144217

result:

ok 1 number(s): "144217"

Test #10:

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

input:

99999 149998
51151 43399 0
51151 43399 1
45978 28343 0
28343 9008 0
85724 9008 0
45978 9008 1
45978 85724 1
28343 85724 1
79446 12915 0
12915 65925 0
28869 65925 0
79446 65925 1
79446 28869 1
12915 28869 1
82642 95556 0
95556 68817 0
68334 68817 0
82642 68817 1
82642 68334 1
95556 68334 1
61212 7638...

output:

144219

result:

ok 1 number(s): "144219"

Test #11:

score: 0
Accepted
time: 89ms
memory: 16192kb

input:

100000 149999
26736 28785 0
28785 37945 0
26736 28785 1
26736 37945 1
1240 74368 0
74368 45022 0
1240 74368 1
1240 45022 1
40673 1276 0
1276 56395 0
40673 1276 1
40673 56395 1
35181 63341 0
63341 35131 0
60120 35131 0
35181 35131 1
35181 60120 1
63341 60120 1
99363 36973 0
99363 36973 1
85717 77683 ...

output:

144380

result:

ok 1 number(s): "144380"

Test #12:

score: 0
Accepted
time: 83ms
memory: 15776kb

input:

100000 150000
63695 11044 0
11044 34978 0
56531 34978 0
63695 34978 1
63695 56531 1
11044 56531 1
72139 3715 0
3715 21024 0
96696 21024 0
72139 21024 1
72139 96696 1
3715 96696 1
54670 49014 0
54670 49014 1
7670 61055 0
61055 38409 0
7670 61055 1
7670 38409 1
83399 50676 0
50676 98893 0
60069 98893 ...

output:

144559

result:

ok 1 number(s): "144559"

Test #13:

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

input:

1 0

output:

1

result:

ok 1 number(s): "1"

Test #14:

score: 0
Accepted
time: 31ms
memory: 9784kb

input:

100000 0

output:

100000

result:

ok 1 number(s): "100000"

Test #15:

score: 0
Accepted
time: 120ms
memory: 15560kb

input:

100000 150000
95066 31960 0
31960 89758 0
10935 89758 0
95066 89758 1
95066 10935 1
31960 10935 1
48016 97823 0
97823 10871 0
23454 10871 0
48016 10871 1
48016 23454 1
97823 23454 1
73749 35525 0
35525 54232 0
42182 54232 0
73749 54232 1
73749 42182 1
35525 42182 1
75405 71341 0
71341 70032 0
3284 7...

output:

125000

result:

ok 1 number(s): "125000"

Test #16:

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

input:

4 6
1 2 0
1 2 1
1 3 0
2 4 1
3 4 0
3 4 1

output:

7

result:

ok 1 number(s): "7"

Test #17:

score: 0
Accepted
time: 42ms
memory: 13308kb

input:

99998 115940
40840 40839 0
28249 28248 0
24785 24783 0
36536 36534 1
71904 71901 1
62023 62021 0
34737 34740 1
18430 18434 0
27506 27505 1
4665 4664 1
36578 36577 1
99311 99314 1
43484 43482 0
26457 26459 1
99698 99695 0
10170 10172 1
98176 98179 1
47786 47785 1
56529 56531 1
86896 86895 1
78204 782...

output:

104913

result:

ok 1 number(s): "104913"

Test #18:

score: 0
Accepted
time: 36ms
memory: 13560kb

input:

99996 126880
57665 57662 0
73031 73028 0
78744 78741 1
36913 36914 0
88139 88138 1
89276 89278 0
66433 66436 1
91069 91070 0
63929 63930 0
89625 89627 0
56400 56399 1
69226 69223 1
88433 88432 1
43807 43810 0
37146 37145 0
43789 43792 1
68123 68124 1
17957 17954 1
82804 82805 0
59808 59804 1
73840 7...

output:

103597

result:

ok 1 number(s): "103597"

Test #19:

score: 0
Accepted
time: 44ms
memory: 13800kb

input:

99996 128661
40089 40092 1
43861 43862 1
75629 75628 0
19597 19598 0
15151 15154 0
95642 95641 0
80320 80317 1
57255 57254 0
35316 35314 0
44675 44676 1
38847 38850 0
50886 50883 1
7617 7615 0
52310 52311 0
71474 71478 1
60036 60035 1
12009 12012 1
72347 72348 1
80343 80345 0
58804 58806 1
11386 113...

output:

103531

result:

ok 1 number(s): "103531"

Test #20:

score: 0
Accepted
time: 33ms
memory: 12312kb

input:

85086 109171
68997 68998 1
24077 24074 0
81830 81829 0
6102 6100 0
16851 16850 0
44103 44101 0
35639 35637 0
46162 46161 1
70373 70372 1
2625 2624 0
50990 50989 0
52220 52219 1
3452 3453 0
21915 21916 0
19561 19564 1
2616 2615 1
59039 59040 1
72589 72590 1
40147 40148 0
83359 83360 1
4274 4275 1
736...

output:

96534

result:

ok 1 number(s): "96534"

Test #21:

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

input:

6 9
1 2 0
1 2 1
1 3 0
2 3 1
3 4 0
4 5 0
4 6 1
5 6 0
5 6 1

output:

10

result:

ok 1 number(s): "10"

Test #22:

score: 0
Accepted
time: 60ms
memory: 13152kb

input:

99998 115940
91307 35051 0
41850 19274 0
35587 78894 0
26695 91651 1
79179 482 1
26680 7283 0
51999 18100 1
97541 51977 0
31565 24059 1
48770 33590 1
79885 37272 1
16578 79254 1
23825 66223 0
51722 3968 1
30481 33229 0
86577 14556 1
63261 87530 1
17567 19857 1
48438 12110 1
68610 47458 1
88373 92315...

output:

104913

result:

ok 1 number(s): "104913"

Test #23:

score: 0
Accepted
time: 60ms
memory: 13684kb

input:

99996 126880
31926 32431 0
89751 77638 0
81312 90949 1
9164 78061 0
79960 37357 1
15044 53165 0
46804 58840 1
96661 32396 0
93436 39774 0
81650 97489 0
28285 25380 1
51642 75847 1
38686 99309 1
65477 46389 0
17012 64436 0
39535 20467 1
55466 34797 1
56580 52438 1
88447 46598 0
94878 81598 1
36359 71...

output:

103597

result:

ok 1 number(s): "103597"

Test #24:

score: 0
Accepted
time: 65ms
memory: 13768kb

input:

99996 128661
68631 18634 1
39185 98747 1
93688 3993 0
63831 49896 0
88466 11249 0
76247 13150 0
44166 89827 1
14706 98796 0
55609 32463 0
96040 11481 1
15800 28436 0
35644 61568 1
90823 7941 0
16497 32517 0
70520 2507 1
36824 37963 1
43899 12185 1
16439 35062 1
22697 5663 0
22986 20940 1
93694 62377...

output:

103531

result:

ok 1 number(s): "103531"

Test #25:

score: 0
Accepted
time: 48ms
memory: 12232kb

input:

85086 109171
54967 52668 1
64243 48915 0
78737 27043 0
69272 84477 0
11191 72192 0
56490 36228 0
52083 25417 0
58946 51014 1
57855 26735 1
83625 46445 0
72878 43133 0
77230 69968 1
7791 38318 0
14928 27213 0
5215 50302 1
75864 25928 1
11582 54867 1
53793 83950 1
70191 16278 0
69499 3665 1
45931 3663...

output:

96534

result:

ok 1 number(s): "96534"

Test #26:

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

input:

100000 150000
99933 55358 0
90416 2554 0
64997 12630 0
43499 35304 0
43164 38359 0
82333 47941 0
15092 76350 1
6401 82373 0
90467 57736 1
72290 58218 0
64844 79192 0
71055 40232 1
54743 65698 0
19204 38062 1
1490 24882 0
18848 1970 1
18829 25405 0
93396 54676 1
5241 60149 0
26699 39910 1
70898 82827...

output:

150000

result:

ok 1 number(s): "150000"

Test #27:

score: 0
Accepted
time: 119ms
memory: 38788kb

input:

100000 130000
15237 21286 1
60817 70086 1
62915 43855 1
23616 97040 1
54175 84281 1
22498 80217 1
58904 98534 0
88649 79847 0
46299 28927 1
90160 25868 1
59368 62900 1
93860 42461 1
2630 7547 1
54787 84637 1
6577 95373 1
62108 8000 1
14358 53523 1
85474 77621 1
68271 30113 1
26333 71197 1
78110 6040...

output:

130000

result:

ok 1 number(s): "130000"

Test #28:

score: 0
Accepted
time: 96ms
memory: 33440kb

input:

65534 98300
42421 54323 0
45888 19783 0
11682 46414 0
41620 27016 0
62650 43400 1
24787 17246 0
38437 37760 0
51438 27810 0
5194 36179 0
42153 44739 0
38012 47581 0
64561 26437 0
30761 19033 0
29631 18563 0
10689 6913 0
9438 48319 0
18569 39847 0
21454 526 0
59916 36345 0
2577 7295 0
22843 14281 0
4...

output:

81918

result:

ok 1 number(s): "81918"

Test #29:

score: 0
Accepted
time: 99ms
memory: 33600kb

input:

65534 98300
44683 25158 1
35394 27103 0
11618 63123 1
26627 62829 1
63124 18531 1
38195 27395 0
30743 3378 1
52310 58855 0
59905 3467 0
60227 44700 0
4466 13169 0
11289 35510 1
45259 23426 1
55348 47991 1
48231 26070 1
48525 16062 1
57931 14114 1
27522 12180 0
12757 20313 1
42080 63292 0
26595 51845...

output:

81918

result:

ok 1 number(s): "81918"

Test #30:

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

input:

65534 98300
13270 32154 0
55961 42311 1
28791 53182 1
59289 50275 1
8038 50111 1
26166 35350 1
11126 60403 1
39908 858 0
59214 30194 1
35679 36357 1
3720 42580 1
24721 42253 1
39094 30603 1
6697 51066 0
3419 63371 1
64362 40934 1
51257 14082 1
63044 59478 1
20968 167 1
30514 42744 1
41849 32144 1
16...

output:

81918

result:

ok 1 number(s): "81918"

Test #31:

score: 0
Accepted
time: 97ms
memory: 32860kb

input:

100000 98302
61966 27142 0
53993 68970 0
34298 58099 1
63874 66725 0
14229 34649 0
2188 81478 0
11724 47884 0
19350 71019 0
61938 51579 0
35352 84486 0
84906 82998 0
14543 39824 0
48746 90624 0
40191 40994 1
47705 23039 0
62784 79792 0
15245 88212 0
92737 95500 0
94811 43930 1
69757 74299 0
53560 49...

output:

116384

result:

ok 1 number(s): "116384"

Test #32:

score: 0
Accepted
time: 102ms
memory: 32664kb

input:

100000 98302
63951 83046 0
49356 1318 1
76776 11042 0
10897 51960 0
91740 36201 1
79579 70160 0
48233 7988 1
77589 73526 0
64917 41777 1
25721 24712 1
40519 61024 0
44493 67177 0
33335 24084 0
3709 42347 0
79762 84853 0
19590 61141 0
77360 58976 0
72886 44054 0
26544 51830 0
5866 45365 0
76622 26661...

output:

124574

result:

ok 1 number(s): "124574"

Test #33:

score: 0
Accepted
time: 104ms
memory: 32724kb

input:

100000 98302
88683 65853 1
85733 28420 1
76008 55360 1
49391 24933 1
87657 14404 1
90800 58622 1
75122 69522 1
22879 73168 1
9291 55797 0
50874 91259 1
86132 9922 1
39521 5711 1
75332 50647 1
14679 89034 1
15252 65542 1
26783 18217 1
11499 26206 1
10487 12140 1
69139 5819 1
62356 90026 1
82272 78670...

output:

116384

result:

ok 1 number(s): "116384"

Test #34:

score: 0
Accepted
time: 208ms
memory: 51352kb

input:

96000 144000
69465 78015 0
70940 79248 0
21267 22945 0
42324 69262 0
92079 61298 0
14312 89231 0
76879 64390 0
9515 87921 0
72921 56907 0
77360 7365 0
5845 31109 0
50706 19916 0
29274 5084 0
27393 91084 0
89690 81434 0
81818 17371 0
59817 87334 0
40802 63933 0
34255 67445 0
84919 73480 0
6355 64057 ...

output:

96000

result:

ok 1 number(s): "96000"

Test #35:

score: 0
Accepted
time: 219ms
memory: 51508kb

input:

98000 147000
64116 52839 0
58466 64469 1
68501 33965 1
35430 29683 1
18936 7790 1
11024 87600 0
87090 27191 1
3526 40531 1
8967 64385 0
74728 9321 1
14888 6420 0
27780 41446 0
56978 5452 0
13425 79329 1
87611 32959 0
3067 17931 0
22989 82933 1
24468 5242 0
47124 59392 1
79914 93411 1
87124 90315 1
7...

output:

98000

result:

ok 1 number(s): "98000"

Test #36:

score: 0
Accepted
time: 221ms
memory: 52244kb

input:

100000 150000
56602 2395 1
82739 49727 1
27928 35973 1
98253 71027 1
35442 98024 1
18060 72579 1
86277 73382 1
47014 51013 1
65310 17335 1
54892 30774 1
77960 822 1
47490 41910 1
62706 85890 1
71056 13146 1
34092 33865 1
58748 46635 1
21972 37259 1
51199 31504 1
43608 87941 1
90790 42330 1
50214 189...

output:

100000

result:

ok 1 number(s): "100000"

Test #37:

score: 0
Accepted
time: 210ms
memory: 50204kb

input:

95000 142500
89254 6524 0
87399 92742 0
50117 8349 0
76363 58825 0
52190 83971 0
6795 20007 0
79651 49566 0
10970 79953 0
11980 53524 0
7467 38087 0
32096 9083 0
17827 38927 0
79988 23057 0
17001 32129 0
56030 42010 0
77569 59418 0
70155 41087 0
27648 77230 0
21167 61067 0
56132 86455 0
80647 19119 ...

output:

95000

result:

ok 1 number(s): "95000"

Test #38:

score: 0
Accepted
time: 215ms
memory: 52752kb

input:

97000 145500
94330 53090 1
74854 79436 0
31002 6670 1
20802 11748 0
23526 78897 0
2600 84830 0
19572 95411 1
87783 55713 0
20454 22602 1
30751 12787 0
67094 60165 0
9477 19434 1
91443 58645 0
49984 1623 0
44709 41427 0
1043 24331 1
79185 42581 0
25102 27915 0
67200 90145 1
25416 40396 1
35961 3087 0...

output:

97000

result:

ok 1 number(s): "97000"

Test #39:

score: 0
Accepted
time: 218ms
memory: 53416kb

input:

99000 148500
63457 58943 1
22274 81761 1
72574 63452 1
67950 79564 1
42979 37610 1
30695 97830 1
33234 77173 1
84106 7156 1
40075 39589 1
41001 66646 1
68993 48814 1
19560 49612 1
80409 70249 1
5995 75043 1
78335 53789 1
87696 94760 1
32934 22366 1
64938 22623 1
49846 19013 1
96854 6968 1
6539 63262...

output:

99000

result:

ok 1 number(s): "99000"

Extra Test:

score: 0
Extra Test Passed