QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293900#7775. 【模板】矩阵快速幂georgeyucjr35 1082ms37136kbC++2319.8kb2023-12-29 22:32:322023-12-29 22:32:33

Judging History

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

  • [2023-12-29 22:32:33]
  • 评测
  • 测评结果:35
  • 用时:1082ms
  • 内存:37136kb
  • [2023-12-29 22:32:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

# if __cplusplus >= 201700LL
# define INLINE_V inline
# else
# define INLINV_V
# endif

#ifndef ATCODER_MODINT_HPP
#define ATCODER_MODINT_HPP 1

#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#endif

#ifndef ATCODER_INTERNAL_MATH_HPP
#define ATCODER_INTERNAL_MATH_HPP 1

#include <utility>

#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
  x %= m;
  if (x < 0)
    x += m;
  return x;
}

// Fast modular multiplication by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
  unsigned int _m;
  unsigned long long im;

  // @param m `1 <= m < 2^31`
  barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}

  // @return m
  unsigned int umod() const { return _m; }

  // @param a `0 <= a < m`
  // @param b `0 <= b < m`
  // @return `a * b % m`
  unsigned int mul(unsigned int a, unsigned int b) const {
    // [1] m = 1
    // a = b = im = 0, so okay

    // [2] m >= 2
    // im = ceil(2^64 / m)
    // -> im * m = 2^64 + r (0 <= r < m)
    // let z = a*b = c*m + d (0 <= c, d < m)
    // a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
    // c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) < 2^64 * 2
    // ((ab * im) >> 64) == c or c + 1
    unsigned long long z = a;
    z *= b;
#ifdef _MSC_VER
    unsigned long long x;
    _umul128(z, im, &x);
#else
    unsigned long long x = (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
    unsigned int v = (unsigned int)(z - x * _m);
    if (_m <= v)
      v += _m;
    return v;
  }
};

// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
  if (m == 1)
    return 0;
  unsigned int _m = (unsigned int)(m);
  unsigned long long r = 1;
  unsigned long long y = safe_mod(x, m);
  while (n) {
    if (n & 1)
      r = (r * y) % _m;
    y = (y * y) % _m;
    n >>= 1;
  }
  return r;
}

// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
  if (n <= 1)
    return false;
  if (n == 2 || n == 7 || n == 61)
    return true;
  if (n % 2 == 0)
    return false;
  long long d = n - 1;
  while (d % 2 == 0)
    d /= 2;
  constexpr long long bases[3] = {2, 7, 61};
  for (long long a : bases) {
    long long t = d;
    long long y = pow_mod_constexpr(a, t, n);
    while (t != n - 1 && y != 1 && y != n - 1) {
      y = y * y % n;
      t <<= 1;
    }
    if (y != n - 1 && t % 2 == 0) {
      return false;
    }
  }
  return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);

// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
  a = safe_mod(a, b);
  if (a == 0)
    return {b, 0};

  // Contracts:
  // [1] s - m0 * a = 0 (mod b)
  // [2] t - m1 * a = 0 (mod b)
  // [3] s * |m1| + t * |m0| <= b
  long long s = b, t = a;
  long long m0 = 0, m1 = 1;

  while (t) {
    long long u = s / t;
    s -= t * u;
    m0 -= m1 * u; // |m1 * u| <= |m1| * s <= b

    // [3]:
    // (s - t * u) * |m1| + t * |m0 - m1 * u|
    // <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
    // = s * |m1| + t * |m0| <= b

    auto tmp = s;
    s = t;
    t = tmp;
    tmp = m0;
    m0 = m1;
    m1 = tmp;
  }
  // by [3]: |m0| <= b/g
  // by g != b: |m0| < b/g
  if (m0 < 0)
    m0 += b / s;
  return {s, m0};
}

// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
constexpr int primitive_root_constexpr(int m) {
  if (m == 2)
    return 1;
  if (m == 167772161)
    return 3;
  if (m == 469762049)
    return 3;
  if (m == 754974721)
    return 11;
  if (m == 998244353)
    return 3;
  int divs[20] = {};
  divs[0] = 2;
  int cnt = 1;
  int x = (m - 1) / 2;
  while (x % 2 == 0)
    x /= 2;
  for (int i = 3; (long long)(i)*i <= x; i += 2) {
    if (x % i == 0) {
      divs[cnt++] = i;
      while (x % i == 0) {
        x /= i;
      }
    }
  }
  if (x > 1) {
    divs[cnt++] = x;
  }
  for (int g = 2;; g++) {
    bool ok = true;
    for (int i = 0; i < cnt; i++) {
      if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
        ok = false;
        break;
      }
    }
    if (ok)
      return g;
  }
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);

} // namespace internal

} // namespace atcoder

#endif // ATCODER_INTERNAL_MATH_HPP

#ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP
#define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1

namespace atcoder {

namespace internal {

#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128>::value, std::true_type, std::false_type>::type;

template <class T>
using is_unsigned_int128 = typename std::conditional<std::is_same<T, __uint128_t>::value || std::is_same<T, unsigned __int128>::value, std::true_type,
                                                     std::false_type>::type;

template <class T> using make_unsigned_int128 = typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t, unsigned __int128>;

template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value || is_signed_int128<T>::value || is_unsigned_int128<T>::value,
                                              std::true_type, std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value && std::is_signed<T>::value) || is_signed_int128<T>::value, std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int = typename std::conditional<(is_integral<T>::value && std::is_unsigned<T>::value) || is_unsigned_int128<T>::value,
                                                  std::true_type, std::false_type>::type;

template <class T>
using to_unsigned =
    typename std::conditional<is_signed_int128<T>::value, make_unsigned_int128<T>,
                              typename std::conditional<std::is_signed<T>::value, std::make_unsigned<T>, std::common_type<T>>::type>::type;

#else

template <class T> using is_integral = typename std::is_integral<T>;

template <class T>
using is_signed_int = typename std::conditional<is_integral<T>::value && std::is_signed<T>::value, std::true_type, std::false_type>::type;

template <class T>
using is_unsigned_int = typename std::conditional<is_integral<T>::value && std::is_unsigned<T>::value, std::true_type, std::false_type>::type;

template <class T> using to_unsigned = typename std::conditional<is_signed_int<T>::value, std::make_unsigned<T>, std::common_type<T>>::type;

#endif

template <class T> using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T> using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

} // namespace internal

} // namespace atcoder

#endif // ATCODER_INTERNAL_TYPE_TRAITS_HPP

namespace atcoder {

namespace internal {

struct modint_base {};
struct static_modint_base : modint_base {};

template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;

} // namespace internal

template <int m, std::enable_if_t<(1 <= m)> * = nullptr> struct static_modint : internal::static_modint_base {
  using mint = static_modint;

public:
  static constexpr int mod() { return m; }
  static mint raw(int v) {
    mint x;
    x._v = v;
    return x;
  }

  static_modint() : _v(0) {}
  template <class T, internal::is_signed_int_t<T> * = nullptr> static_modint(T v) {
    long long x = (long long)(v % (long long)(umod()));
    if (x < 0)
      x += umod();
    _v = (unsigned int)(x);
  }
  template <class T, internal::is_unsigned_int_t<T> * = nullptr> static_modint(T v) { _v = (unsigned int)(v % umod()); }

  unsigned int val() const { return _v; }

  mint &operator++() {
    _v++;
    if (_v == umod())
      _v = 0;
    return *this;
  }
  mint &operator--() {
    if (_v == 0)
      _v = umod();
    _v--;
    return *this;
  }
  mint operator++(int) {
    mint result = *this;
    ++*this;
    return result;
  }
  mint operator--(int) {
    mint result = *this;
    --*this;
    return result;
  }

  mint &operator+=(const mint &rhs) {
    _v += rhs._v;
    if (_v >= umod())
      _v -= umod();
    return *this;
  }
  mint &operator-=(const mint &rhs) {
    _v -= rhs._v;
    if (_v >= umod())
      _v += umod();
    return *this;
  }
  mint &operator*=(const mint &rhs) {
    unsigned long long z = _v;
    z *= rhs._v;
    _v = (unsigned int)(z % umod());
    return *this;
  }
  mint &operator/=(const mint &rhs) { return *this = *this * rhs.inv(); }

  mint operator+() const { return *this; }
  mint operator-() const { return mint() - *this; }

  mint pow(long long n) const {
    assert(0 <= n);
    mint x = *this, r = 1;
    while (n) {
      if (n & 1)
        r *= x;
      x *= x;
      n >>= 1;
    }
    return r;
  }
  mint inv() const {
    if (prime) {
      assert(_v);
      return pow(umod() - 2);
    } else {
      auto eg = internal::inv_gcd(_v, m);
      assert(eg.first == 1);
      return eg.second;
    }
  }

  friend mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; }
  friend mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; }
  friend mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; }
  friend mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; }
  friend bool operator==(const mint &lhs, const mint &rhs) { return lhs._v == rhs._v; }
  friend bool operator!=(const mint &lhs, const mint &rhs) { return lhs._v != rhs._v; }

private:
  unsigned int _v;
  static constexpr unsigned int umod() { return m; }
  static constexpr bool prime = internal::is_prime<m>;
};

template <int id> struct dynamic_modint : internal::modint_base {
  using mint = dynamic_modint;

public:
  static int mod() { return (int)(bt.umod()); }
  static void set_mod(int m) {
    assert(1 <= m);
    bt = internal::barrett(m);
  }
  static mint raw(int v) {
    mint x;
    x._v = v;
    return x;
  }

  dynamic_modint() : _v(0) {}
  template <class T, internal::is_signed_int_t<T> * = nullptr> dynamic_modint(T v) {
    long long x = (long long)(v % (long long)(mod()));
    if (x < 0)
      x += mod();
    _v = (unsigned int)(x);
  }
  template <class T, internal::is_unsigned_int_t<T> * = nullptr> dynamic_modint(T v) { _v = (unsigned int)(v % mod()); }

  unsigned int val() const { return _v; }

  mint &operator++() {
    _v++;
    if (_v == umod())
      _v = 0;
    return *this;
  }
  mint &operator--() {
    if (_v == 0)
      _v = umod();
    _v--;
    return *this;
  }
  mint operator++(int) {
    mint result = *this;
    ++*this;
    return result;
  }
  mint operator--(int) {
    mint result = *this;
    --*this;
    return result;
  }

  mint &operator+=(const mint &rhs) {
    _v += rhs._v;
    if (_v >= umod())
      _v -= umod();
    return *this;
  }
  mint &operator-=(const mint &rhs) {
    _v += mod() - rhs._v;
    if (_v >= umod())
      _v -= umod();
    return *this;
  }
  mint &operator*=(const mint &rhs) {
    _v = bt.mul(_v, rhs._v);
    return *this;
  }
  mint &operator/=(const mint &rhs) { return *this = *this * rhs.inv(); }

  mint operator+() const { return *this; }
  mint operator-() const { return mint() - *this; }

  mint pow(long long n) const {
    assert(0 <= n);
    mint x = *this, r = 1;
    while (n) {
      if (n & 1)
        r *= x;
      x *= x;
      n >>= 1;
    }
    return r;
  }
  mint inv() const {
    auto eg = internal::inv_gcd(_v, mod());
    assert(eg.first == 1);
    return eg.second;
  }

  friend mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; }
  friend mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; }
  friend mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; }
  friend mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; }
  friend bool operator==(const mint &lhs, const mint &rhs) { return lhs._v == rhs._v; }
  friend bool operator!=(const mint &lhs, const mint &rhs) { return lhs._v != rhs._v; }

private:
  unsigned int _v;
  static internal::barrett bt;
  static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt = 998244353;

using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;

namespace internal {

template <class T> using is_static_modint = std::is_base_of<internal::static_modint_base, T>;

template <class T> using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;

template <class> struct is_dynamic_modint : public std::false_type {};
template <int id> struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};

template <class T> using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;

} // namespace internal

} // namespace atcoder

#endif // ATCODER_MODINT_HPP

#define ll long long
#define ull unsigned long long
#define rep(i, f, t, ...) for (int i = f, ##__VA_ARGS__; i <= t; ++i)
#define red(i, f, t, ...) for (int i = f, ##__VA_ARGS__; i >= t; --i)
#define emb emplace_back
#define pb push_back
#define pii pair<int, int>
#define mkp make_pair
#define arr3 array<int, 3>
#define arr4 array<int, 4>
#define FILEIO(filename) freopen(filename ".in", "r", stdin), freopen(filename ".out", "w", stdout)
#define ALrep(vc) vc.begin(), vc.end()
#define N 605
template <class T> constexpr static T inf = numeric_limits<T>::max() / 10;

#ifdef MACOS
#include "/Users/yzw/GeorgeYuOI/codes/cpp/georgeyucjr/debug/debug.hpp"
using namespace georgeyucjr;
#else
#define write(...) void(36)
#define bug(...) void(36)
#endif

bool Mst;

using mint = atcoder::modint998244353;
using i128 = __int128_t;
using db = long double;
INLINE_V constexpr static i128 VAL1 = 2e18;
INLINE_V constexpr static i128 VAL2 = 1e31;
INLINE_V constexpr static i128 VAL3 = 1e27;

int n, m, Eu[N], Ev[N];
ll k, Ew[N];

namespace Solve1 { // k <= 2 * n * n

i128 dis[N], updis[N];
inline void span() {
  fill(updis + 1, updis + n + 1, 2 * inf<i128>);
  rep(i, 1, m) updis[Ev[i]] = min(updis[Ev[i]], dis[Eu[i]] + Ew[i]);
  copy_n(updis + 1, n, dis + 1);
}
i128 cyc[N][N], ray[N][N];

inline void SLVR() {
  fill(dis + 1, dis + n + 1, 2 * inf<i128>);
  dis[1] = 0;
  ll LEN = n * (n + 1) * 3;
  if (k <= 2 * LEN)
    rep(t, 1, k) span();
  else {
    ll mid = k - LEN * 2;
    rep(i, 1, n) {
      fill(dis + 1, dis + n + 1, 2 * inf<i128>);
      dis[i] = 0;
      rep(t, 1, n) span(), cyc[i][t] = ((dis[i] < inf<i128>) ? (dis[i]) : (-1));
    }
    fill(dis + 1, dis + n + 1, 2 * inf<i128>);
    dis[1] = 0;
    rep(t, 1, LEN) span();
    rep(i, 1, n) rep(j, 1, n) ray[i][j] = 2 * inf<i128>;
    rep(i, 1, n) if (dis[i] < inf<i128>) rep(j, 1, n) if (~cyc[i][j]) {
        ll t = mid / j + 1;
        ll sm = t * j - mid;
        ray[sm][i] = min(ray[sm][i], dis[i] + (i128)t * cyc[i][j]);
			}
    fill(dis + 1, dis + n + 1, 2 * inf<i128>);
    rep(t, 1, LEN) {
      span();
      if (t <= n)
        rep(i, 1, n) dis[i] = min(dis[i], ray[t][i]);
    }
  }
  rep(i, 1, n) cout << ( dis[i] > inf < i128 > ? -1 : ( int ) mint ( dis[i] ).val ( ) ) << ( i == n ? "\n" : " ");
}
} // namespace Solve1
namespace Solve2 { // k > 2 * n * n
i128 dis[N], updis[N];
struct Frac {
  int L;
  i128 S;
  Frac(i128 sum = 0, int len = 0) { L = len, S = sum; }
};
inline bool operator<(const Frac &lhs, const Frac &rhs) { return lhs.S * rhs.L < rhs.S * lhs.L; }
inline bool operator==(const Frac &lhs, const Frac &rhs) { return lhs.S * rhs.L == rhs.S * lhs.L; }

struct Node {
  Frac a, b;
  Node(Frac A = Frac(1, 1), Frac B = Frac(1, 1)) { a = A, b = B; }
};

bool flag;
i128 K, LIM;

inline bool operator<(const Node &x, const Node &y) {
  i128 vl1 = x.a.S * y.a.L;
  i128 vl2 = x.a.L * y.a.S;
  if (vl1 == vl2)
    return x.b < y.b;
  if (flag)
    return vl1 < vl2;
  i128 dt = vl1 - vl2;
  return (-LIM <= dt && dt <= LIM) ? dt * K + x.b.S * y.b.L < x.b.L * y.b.S : vl1 < vl2;
}

INLINE_V const static Node Nd_inf = Node(Frac(VAL2, 1), Frac(VAL2, 1));

inline void span() {
  fill(updis + 1, updis + n + 1, 2 * inf<i128>);
  rep(i, 1, m) updis[Ev[i]] = min(updis[Ev[i]], dis[Eu[i]] + Ew[i]);
  copy_n (updis + 1, n, dis + 1);
}

Node tempdis[N], tempud[N];
inline void SAP() {
  fill(tempud + 1, tempud + n + 1, Nd_inf);
  rep(i, 1, m) {
    auto cur = tempdis[Eu[i]];
    cur.b.S += (__int128)Ew[i] * cur.b.L;
    tempud[Ev[i]] = min(tempud[Ev[i]], cur);
  }
  copy_n(tempud + 1, n, tempdis + 1);
}
i128 cyc[N][N];
Node ray[N][N];

inline void SLVR(string S) {
  fill(dis + 1, dis + n + 1, 2 * inf<i128>);
	dis[1] = 0;
  ll LEN = n * (n + 1) * 2;

  db tmp = 0;
  for (auto ch : S)
    tmp = tmp * 10 + (ch ^ 48);
  if (tmp > VAL3) {
    flag = true;
  } else {
    flag = false;
    K = 0;
    for (auto c : S)
      K = K * 10 + (c ^ 48);
    K -= LEN * 2;
    if (K)
      LIM = 2e36 / K;
  }

  rep(i, 1, n) {
    fill(dis + 1, dis + n + 1, 2 * inf<i128>);
    dis[i] = 0;
    rep(t, 1, n) span(), cyc[i][t] = dis[i] < inf<i128> ? dis[i] : -1;
  }
  fill(dis + 1, dis + n + 1, 2 * inf<i128>);
  dis[1] = 0;
  rep(t, 1, LEN) span();

  vector<int> mds(n + 1);
  rep(i, 1, n) {
    int w = 0;
    for (auto &r : S)
      w = w * 10 + r ^ 48, w %= i;
    mds[i] = ((w - LEN * 2) % i + i) % i;
  }

  rep(i, 1, n) rep(j, 1, n) ray[i][j] = Nd_inf;
  rep(i, 1, n) if (dis[i] < inf<i128>) rep(j, 1, n, md, sm) if (~cyc[i][j])
      sm = j - (md = mds[j]),
      ray[sm][i] = min(ray[sm][i], Node(Frac(cyc[i][j], j), Frac(dis[i] * j + sm * cyc[i][j], j)));
  rep(i, 1, n) tempdis[i] = Nd_inf;
  rep(t, 1, LEN) {
    SAP();
    if (t <= n)
      rep(i, 1, n) tempdis[i] = min(tempdis[i], ray[t][i]);
  }
  mint num = 0;
  for (auto ch : S)
    (num *= 10) += ch ^ 48;
  num -= LEN * 2;

  rep(i, 1, n) {
    auto r = tempdis[i];
    if ((db)r.a.S / r.a.L > VAL1)
      cout << -1 << " ";
    else
      cout << ((num * r.a.S + r.b.S) * mint(r.b.L).inv()).val() << " ";
  }
  cout << endl;
}
} // namespace Solve2

bool Med;

signed main() {
#ifndef ONLINE_JUDGE
  freopen("ex_matrix2.in", "r", stdin), freopen("P10000.out", "w", stdout);
  // FILEIO("P10000");
#endif
  ios_base ::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  auto slv = [&]() {
    string S;
    cin >> n >> m >> S;
    db tmp = 0;
    for (auto ch : S)
      tmp = tmp * 10 + (ch ^ 48);
    rep(i, 1, m) cin >> Eu[i] >> Ev[i] >> Ew[i];
    if (tmp <= n * n * 10) {
      k = 0;
      for (auto ch : S)
        k = k * 10 + (ch ^ 48);
      Solve1::SLVR();
      return;
    }
    Solve2::SLVR(S);
  };
  int T;
  cin >> T >> T;
  while (T--)
    slv();

#ifdef MACOS
  cerr << "Memory & Time Information : " << endl;
  cerr << "Memory : " << ((&Med) - (&Mst)) * 1. / 1024. / 1024. << "MB" << endl;
  cerr << "Time : " << clock() * 1. / CLOCKS_PER_SEC * 1000. << "ms" << endl;
#endif
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 23ms
memory: 31472kb

input:

1
1
100 101 899539897889989959
74 35 910832669819965536
35 85 910832669819965536
85 88 910832669819965536
88 30 910832669819965536
30 58 910832669819965536
58 60 910832669819965536
60 34 910832669819965536
34 8 910832669819965536
8 67 910832669819965536
67 89 910832669819965536
89 32 910832669819965...

output:

395495796 395495785 395495787 395495843 395495797 395495793 395495758 395495836 395495849 395495759 395495827 395495777 395495757 395495804 395495786 395495767 395495751 395495765 395495798 395495795 395495790 395495825 395495802 395495769 395495776 395495774 395495761 395495823 395495847 395495832 ...

result:

wrong answer 1st numbers differ - expected: '395495792', found: '395495796'

Subtask #2:

score: 15
Accepted

Test #7:

score: 15
Accepted
time: 1032ms
memory: 32392kb

input:

2
1
300 598 8179377797889487867988994778539839593376697796496698959964978969
1 2 977880533270721156
2 1 977880533270721156
2 3 977880533270721156
3 2 977880533270721156
3 4 977880533270721156
4 3 977880533270721156
4 5 977880533270721156
5 4 977880533270721156
5 6 977880533270721156
6 5 977880533270...

output:

-1 313446627 -1 313436465 -1 313426303 -1 313416141 -1 313405979 -1 313395817 -1 313385655 -1 313375493 -1 313365331 -1 313355169 -1 313345007 -1 313334845 -1 313324683 -1 313314521 -1 313304359 -1 313294197 -1 313284035 -1 313273873 -1 313263711 -1 313253549 -1 313243387 -1 313233225 -1 313223063 -...

result:

ok 300 numbers

Test #8:

score: 0
Accepted
time: 1035ms
memory: 32976kb

input:

2
1
300 598 9284745978997975899894787995823975998931999649789777849997467689
1 2 946893593823801228
2 1 946893593823801228
2 3 761384824565158999
3 2 761384824565158999
3 4 642721010434291429
4 3 642721010434291429
4 5 936762490761905983
5 4 936762490761905983
5 6 785485094128355256
6 5 785485094128...

output:

-1 613575042 -1 416269325 -1 387291578 -1 980556870 -1 491367967 -1 221793101 -1 191668085 -1 356035653 -1 428450970 -1 964149805 -1 511723806 -1 423081033 -1 947783979 -1 325795034 -1 115778037 -1 86469999 -1 111666379 -1 386592847 -1 223100328 -1 381885001 -1 23001328 -1 84087613 -1 517941041 -1 9...

result:

ok 300 numbers

Test #9:

score: 0
Accepted
time: 1037ms
memory: 33112kb

input:

2
1
300 598 7877597936928589688789427798322599997378688496694695996269389696
1 2 866412995946330002
2 1 866412995946330002
2 3 866412995946330002
3 2 866412995946330002
3 4 866412995946330002
4 3 866412995946330002
4 5 866412995946330002
5 4 866412995946330002
5 6 866412995946330002
6 5 866412995946...

output:

708443714 -1 708438498 -1 708433282 -1 708428066 -1 708422850 -1 708417634 -1 708412418 -1 708407202 -1 708401986 -1 708396770 -1 708391554 -1 708386338 -1 708381122 -1 708375906 -1 708370690 -1 708365474 -1 708360258 -1 708355042 -1 708349826 -1 708344610 -1 708339394 -1 708334178 -1 708328962 -1 7...

result:

ok 300 numbers

Test #10:

score: 0
Accepted
time: 1058ms
memory: 32684kb

input:

2
1
300 598 74686617152792803
1 2 920869599353968456
2 1 920869599353968456
2 3 920869599353968456
3 2 920869599353968456
3 4 920869599353968456
4 3 920869599353968456
4 5 920869599353968456
5 4 920869599353968456
5 6 920869599353968456
6 5 920869599353968456
6 7 920869599353968456
7 6 9208695993539...

output:

-1 537762223 -1 537752459 -1 537742695 -1 537732931 -1 537723167 -1 537713403 -1 537703639 -1 537693875 -1 537684111 -1 537674347 -1 537664583 -1 537654819 -1 537645055 -1 537635291 -1 537625527 -1 537615763 -1 537605999 -1 537596235 -1 537586471 -1 537576707 -1 537566943 -1 537557179 -1 537547415 -...

result:

ok 300 numbers

Test #11:

score: 0
Accepted
time: 648ms
memory: 37136kb

input:

2
40
120 238 7647979978895986883485788838258737687493899697379499657768989994
1 2 940784508355800649
2 1 940784508355800649
2 3 940784508355800649
3 2 940784508355800649
3 4 940784508355800649
4 3 940784508355800649
4 5 940784508355800649
5 4 940784508355800649
5 6 940784508355800649
6 5 94078450835...

output:

383704267 -1 383701847 -1 383699427 -1 383697007 -1 383694587 -1 383692167 -1 383689747 -1 383687327 -1 383684907 -1 383682487 -1 383680067 -1 383677647 -1 383675227 -1 383672807 -1 383670387 -1 383667967 -1 383665547 -1 383663127 -1 383660707 -1 383658287 -1 383655867 -1 383653447 -1 383651027 -1 3...

result:

ok 3146 numbers

Test #12:

score: 0
Accepted
time: 665ms
memory: 34120kb

input:

2
5697
96 190 8939398847797777979859997957885578698889795859699765658877967896
1 2 940438543633266209
2 1 940438543633266209
2 3 940438543633266209
3 2 940438543633266209
3 4 940438543633266209
4 3 940438543633266209
4 5 940438543633266209
5 4 940438543633266209
5 6 940438543633266209
6 5 9404385436...

output:

57861585 -1 57859879 -1 57858173 -1 57856467 -1 57854761 -1 57853055 -1 57851349 -1 57849643 -1 57847937 -1 57846231 -1 57844525 -1 57842819 -1 57841113 -1 57839407 -1 57837701 -1 57835995 -1 57834289 -1 57832583 -1 57830877 -1 57829171 -1 57827465 -1 57825759 -1 57824053 -1 57822347 -1 57820641 -1 ...

result:

ok 77560 numbers

Subtask #3:

score: 20
Accepted

Dependency #2:

100%
Accepted

Test #13:

score: 20
Accepted
time: 1037ms
memory: 32188kb

input:

3
1
300 600 9479768887366979469968967538414386738799799469768954967897479478
235 118 610005418879451235
118 235 610005418879451235
229 118 610005418879451235
118 229 610005418879451235
36 235 610005418879451235
235 36 610005418879451235
265 229 610005418879451235
229 265 610005418879451235
24 36 610...

output:

494335567 494326423 494248699 494244127 494344711 494326423 494358427 494335567 494362999 494303563 494344711 494294419 494344711 494344711 494239555 494285275 494298991 494335567 494294419 494221267 494344711 494353855 494289847 494404147 494298991 494294419 494230411 494253271 494230411 494367571 ...

result:

ok 300 numbers

Test #14:

score: 0
Accepted
time: 1037ms
memory: 32776kb

input:

3
1
300 600 5776769948887747678764766855867697879888989838869789796489887868
283 274 755089058915384251
274 283 755089058915384251
244 283 888168172221533892
283 244 888168172221533892
282 283 888128579062348874
283 282 888128579062348874
40 244 889268402435235212
244 40 889268402435235212
182 282 9...

output:

176036896 694748344 -1 -1 -1 -1 600566244 -1 -1 -1 -1 -1 718827887 436968623 37585847 -1 -1 504374914 -1 633560024 856820739 157217839 -1 306684175 563519989 184280158 797877375 730487505 574440187 141621833 108771729 627363885 6744545 -1 216801629 -1 -1 -1 -1 635875737 -1 -1 -1 172431836 -1 7053201...

result:

ok 300 numbers

Test #15:

score: 0
Accepted
time: 1082ms
memory: 33556kb

input:

3
1
300 600 7799975936983268595994769498698386999688649798971695584484797589
213 87 992365484371550852
87 213 992365484371550852
292 213 992365484371550852
213 292 992365484371550852
125 292 992365484371550852
292 125 992365484371550852
32 213 992365484371550852
213 32 992365484371550852
231 32 9923...

output:

-1 352350370 352353940 352300390 -1 352257550 352357510 -1 -1 -1 -1 -1 352303960 -1 -1 -1 352328950 -1 -1 352353940 -1 -1 352346800 352325380 352368220 -1 352368220 352325380 -1 352339660 352368220 352278970 352343230 -1 -1 -1 -1 -1 -1 -1 -1 -1 352261120 -1 352314670 352311100 -1 -1 352371790 352275...

result:

ok 300 numbers

Test #16:

score: 0
Accepted
time: 1059ms
memory: 31416kb

input:

3
1
300 600 108915867328921644
78 120 915329174369582501
120 78 915329174369582501
166 120 915329174369582501
120 166 915329174369582501
24 120 915329174369582501
120 24 915329174369582501
2 24 915329174369582501
24 2 915329174369582501
146 2 915329174369582501
2 146 915329174369582501
266 2 9153291...

output:

796638071 796675403 796642219 796633923 796625627 796613183 796621479 796625627 796600739 796609035 796617331 796625627 796617331 796621479 796625627 796600739 796629775 796579999 796675403 796613183 796625627 796617331 796604887 796671255 796629775 796675403 796658811 796596591 796600739 796625627 ...

result:

ok 300 numbers

Test #17:

score: 0
Accepted
time: 643ms
memory: 33668kb

input:

3
48
120 240 7737895866885999885898998578585996398987747885374658446818863997
97 35 804386118934281915
35 97 804386118934281915
59 35 804386118934281915
35 59 804386118934281915
111 35 804386118934281915
35 111 804386118934281915
62 111 804386118934281915
111 62 804386118934281915
54 59 804386118934...

output:

-1 817576206 817570296 -1 -1 -1 -1 817576206 817576206 -1 -1 -1 817577388 -1 817575024 817573842 817576206 -1 -1 -1 -1 817569114 817573842 -1 817578570 817579752 817578570 -1 -1 -1 817575024 -1 817570296 -1 -1 -1 817577388 817576206 -1 -1 817571478 817575024 -1 -1 817571478 817571478 817572660 81757...

result:

ok 3516 numbers

Test #18:

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

input:

3
6185
96 192 9829599865896867589898965976864696579885564749989527653879744756
27 20 972718145577806019
20 27 972718145577806019
11 27 972718145577806019
27 11 972718145577806019
44 11 972718145577806019
11 44 972718145577806019
70 11 972718145577806019
11 70 972718145577806019
57 44 972718145577806...

output:

432574626 -1 432575632 -1 432569596 432580662 432581668 -1 432577644 432579656 432583680 432571608 432582674 432582674 -1 432570602 -1 432576638 -1 432584686 -1 -1 -1 -1 432582674 432575632 -1 432576638 432573620 -1 432583680 432570602 -1 432580662 432577644 -1 -1 432578650 -1 432575632 -1 432572614...

result:

ok 83979 numbers

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

100%
Accepted

Dependency #4:

0%