QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#349044#8333. Giftucup-team987#AC ✓100ms56480kbC++2020.1kb2024-03-09 23:18:572024-03-09 23:18:58

Judging History

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

  • [2024-03-09 23:18:58]
  • 评测
  • 测评结果:AC
  • 用时:100ms
  • 内存:56480kb
  • [2024-03-09 23:18:57]
  • 提交

answer

/**
 * date   : 2024-03-10 00:18:41
 * author : Nyaan
 */

#define NDEBUG

using namespace std;

// intrinstic
#include <immintrin.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

// utility

namespace Nyaan {
using ll = long long;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;

template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
using vi = vector<int>;
using vl = vector<long long>;
using vd = V<double>;
using vs = V<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template <typename T, typename U>
struct P : pair<T, U> {
  template <typename... Args>
  P(Args... args) : pair<T, U>(args...) {}

  using pair<T, U>::first;
  using pair<T, U>::second;

  P &operator+=(const P &r) {
    first += r.first;
    second += r.second;
    return *this;
  }
  P &operator-=(const P &r) {
    first -= r.first;
    second -= r.second;
    return *this;
  }
  P &operator*=(const P &r) {
    first *= r.first;
    second *= r.second;
    return *this;
  }
  template <typename S>
  P &operator*=(const S &r) {
    first *= r, second *= r;
    return *this;
  }
  P operator+(const P &r) const { return P(*this) += r; }
  P operator-(const P &r) const { return P(*this) -= r; }
  P operator*(const P &r) const { return P(*this) *= r; }
  template <typename S>
  P operator*(const S &r) const {
    return P(*this) *= r;
  }
  P operator-() const { return P{-first, -second}; }
};

using pl = P<ll, ll>;
using pi = P<int, int>;
using vp = V<pl>;

constexpr int inf = 1001001001;
constexpr long long infLL = 4004004004004004004LL;

template <typename T>
int sz(const T &t) {
  return t.size();
}

template <typename T, typename U>
inline bool amin(T &x, U y) {
  return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U>
inline bool amax(T &x, U y) {
  return (x < y) ? (x = y, true) : false;
}

template <typename T>
inline T Max(const vector<T> &v) {
  return *max_element(begin(v), end(v));
}
template <typename T>
inline T Min(const vector<T> &v) {
  return *min_element(begin(v), end(v));
}
template <typename T>
inline long long Sum(const vector<T> &v) {
  return accumulate(begin(v), end(v), 0LL);
}

template <typename T>
int lb(const vector<T> &v, const T &a) {
  return lower_bound(begin(v), end(v), a) - begin(v);
}
template <typename T>
int ub(const vector<T> &v, const T &a) {
  return upper_bound(begin(v), end(v), a) - begin(v);
}

constexpr long long TEN(int n) {
  long long ret = 1, x = 10;
  for (; n; x *= x, n >>= 1) ret *= (n & 1 ? x : 1);
  return ret;
}

template <typename T, typename U>
pair<T, U> mkp(const T &t, const U &u) {
  return make_pair(t, u);
}

template <typename T>
vector<T> mkrui(const vector<T> &v, bool rev = false) {
  vector<T> ret(v.size() + 1);
  if (rev) {
    for (int i = int(v.size()) - 1; i >= 0; i--) ret[i] = v[i] + ret[i + 1];
  } else {
    for (int i = 0; i < int(v.size()); i++) ret[i + 1] = ret[i] + v[i];
  }
  return ret;
};

template <typename T>
vector<T> mkuni(const vector<T> &v) {
  vector<T> ret(v);
  sort(ret.begin(), ret.end());
  ret.erase(unique(ret.begin(), ret.end()), ret.end());
  return ret;
}

template <typename F>
vector<int> mkord(int N, F f) {
  vector<int> ord(N);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), f);
  return ord;
}

template <typename T>
vector<int> mkinv(vector<T> &v) {
  int max_val = *max_element(begin(v), end(v));
  vector<int> inv(max_val + 1, -1);
  for (int i = 0; i < (int)v.size(); i++) inv[v[i]] = i;
  return inv;
}

vector<int> mkiota(int n) {
  vector<int> ret(n);
  iota(begin(ret), end(ret), 0);
  return ret;
}

template <typename T>
T mkrev(const T &v) {
  T w{v};
  reverse(begin(w), end(w));
  return w;
}

template <typename T>
bool nxp(T &v) {
  return next_permutation(begin(v), end(v));
}

// 返り値の型は入力の T に依存
// i 要素目 : [0, a[i])
template <typename T>
vector<vector<T>> product(const vector<T> &a) {
  vector<vector<T>> ret;
  vector<T> v;
  auto dfs = [&](auto rc, int i) -> void {
    if (i == (int)a.size()) {
      ret.push_back(v);
      return;
    }
    for (int j = 0; j < a[i]; j++) v.push_back(j), rc(rc, i + 1), v.pop_back();
  };
  dfs(dfs, 0);
  return ret;
}

// F : function(void(T&)), mod を取る操作
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I, const function<void(T &)> &f) {
  T res = I;
  for (; n; f(a = a * a), n >>= 1) {
    if (n & 1) f(res = res * a);
  }
  return res;
}
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I = T{1}) {
  return Power(a, n, I, function<void(T &)>{[](T &) -> void {}});
}

template <typename T>
T Rev(const T &v) {
  T res = v;
  reverse(begin(res), end(res));
  return res;
}

template <typename T>
vector<T> Transpose(const vector<T> &v) {
  using U = typename T::value_type;
  int H = v.size(), W = v[0].size();
  vector res(W, T(H, U{}));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      res[j][i] = v[i][j];
    }
  }
  return res;
}

template <typename T>
vector<T> Rotate(const vector<T> &v, int clockwise = true) {
  using U = typename T::value_type;
  int H = v.size(), W = v[0].size();
  vector res(W, T(H, U{}));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (clockwise) {
        res[W - 1 - j][i] = v[i][j];
      } else {
        res[j][H - 1 - i] = v[i][j];
      }
    }
  }
  return res;
}

}  // namespace Nyaan


// bit operation

namespace Nyaan {
__attribute__((target("popcnt"))) inline int popcnt(const u64 &a) {
  return _mm_popcnt_u64(a);
}
inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int ctz(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; }
template <typename T>
inline int gbit(const T &a, int i) {
  return (a >> i) & 1;
}
template <typename T>
inline void sbit(T &a, int i, bool b) {
  if (gbit(a, i) != b) a ^= T(1) << i;
}
constexpr long long PW(int n) { return 1LL << n; }
constexpr long long MSK(int n) { return (1LL << n) - 1; }
}  // namespace Nyaan


// inout

namespace Nyaan {

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  int s = (int)v.size();
  for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

istream &operator>>(istream &is, __int128_t &x) {
  string S;
  is >> S;
  x = 0;
  int flag = 0;
  for (auto &c : S) {
    if (c == '-') {
      flag = true;
      continue;
    }
    x *= 10;
    x += c - '0';
  }
  if (flag) x = -x;
  return is;
}

istream &operator>>(istream &is, __uint128_t &x) {
  string S;
  is >> S;
  x = 0;
  for (auto &c : S) {
    x *= 10;
    x += c - '0';
  }
  return is;
}

ostream &operator<<(ostream &os, __int128_t x) {
  if (x == 0) return os << 0;
  if (x < 0) os << '-', x = -x;
  string S;
  while (x) S.push_back('0' + x % 10), x /= 10;
  reverse(begin(S), end(S));
  return os << S;
}
ostream &operator<<(ostream &os, __uint128_t x) {
  if (x == 0) return os << 0;
  string S;
  while (x) S.push_back('0' + x % 10), x /= 10;
  reverse(begin(S), end(S));
  return os << S;
}

void in() {}
template <typename T, class... U>
void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}

void out() { cout << "\n"; }
template <typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u)) cout << sep;
  out(u...);
}

struct IoSetupNya {
  IoSetupNya() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(7);
  }
} iosetupnya;

}  // namespace Nyaan


// debug


#ifdef NyaanDebug
#define trc(...) (void(0))
#else
#define trc(...) (void(0))
#endif

#ifdef NyaanLocal
#define trc2(...) (void(0))
#else
#define trc2(...) (void(0))
#endif


// macro

#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define all(v) (v).begin(), (v).end()
#define rep(i, N) for (long long i = 0; i < (long long)(N); i++)
#define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--)
#define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++)
#define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--)
#define reg(i, a, b) for (long long i = (a); i < (b); i++)
#define regr(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define fi first
#define se second
#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)
#define inl(...)         \
  long long __VA_ARGS__; \
  in(__VA_ARGS__)
#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__)
#define in2(s, t)                           \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i]);                         \
  }
#define in3(s, t, u)                        \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i], u[i]);                   \
  }
#define in4(s, t, u, v)                     \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i], u[i], v[i]);             \
  }
#define die(...)             \
  do {                       \
    Nyaan::out(__VA_ARGS__); \
    return;                  \
  } while (0)


namespace Nyaan {
void solve();
}
int main() { Nyaan::solve(); }


//


struct UnionFind {
  vector<int> data;
  UnionFind(int N) : data(N, -1) {}

  int find(int k) { return data[k] < 0 ? k : data[k] = find(data[k]); }

  int unite(int x, int y) {
    if ((x = find(x)) == (y = find(y))) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  // f ... merge function
  template<typename F>
  int unite(int x, int y,const F &f) {
    if ((x = find(x)) == (y = find(y))) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    f(x, y);
    return true;
  }

  int size(int k) { return -data[find(k)]; }

  int same(int x, int y) { return find(x) == find(y); }
};

/**
 * @brief Union Find(Disjoint Set Union)
 * @docs docs/data-structure/union-find.md
 */










template <typename T>
struct edge {
  int src, to;
  T cost;

  edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
  edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnweightedGraph = vector<vector<int>>;

// Input of (Unweighted) Graph
UnweightedGraph graph(int N, int M = -1, bool is_directed = false,
                      bool is_1origin = true) {
  UnweightedGraph g(N);
  if (M == -1) M = N - 1;
  for (int _ = 0; _ < M; _++) {
    int x, y;
    cin >> x >> y;
    if (is_1origin) x--, y--;
    g[x].push_back(y);
    if (!is_directed) g[y].push_back(x);
  }
  return g;
}

// Input of Weighted Graph
template <typename T>
WeightedGraph<T> wgraph(int N, int M = -1, bool is_directed = false,
                        bool is_1origin = true) {
  WeightedGraph<T> g(N);
  if (M == -1) M = N - 1;
  for (int _ = 0; _ < M; _++) {
    int x, y;
    cin >> x >> y;
    T c;
    cin >> c;
    if (is_1origin) x--, y--;
    g[x].emplace_back(x, y, c);
    if (!is_directed) g[y].emplace_back(y, x, c);
  }
  return g;
}

// Input of Edges
template <typename T>
Edges<T> esgraph(int N, int M, int is_weighted = true, bool is_1origin = true) {
  Edges<T> es;
  for (int _ = 0; _ < M; _++) {
    int x, y;
    cin >> x >> y;
    T c;
    if (is_weighted)
      cin >> c;
    else
      c = 1;
    if (is_1origin) x--, y--;
    es.emplace_back(x, y, c);
  }
  return es;
}

// Input of Adjacency Matrix
template <typename T>
vector<vector<T>> adjgraph(int N, int M, T INF, int is_weighted = true,
                           bool is_directed = false, bool is_1origin = true) {
  vector<vector<T>> d(N, vector<T>(N, INF));
  for (int _ = 0; _ < M; _++) {
    int x, y;
    cin >> x >> y;
    T c;
    if (is_weighted)
      cin >> c;
    else
      c = 1;
    if (is_1origin) x--, y--;
    d[x][y] = c;
    if (!is_directed) d[y][x] = c;
  }
  return d;
}

/**
 * @brief グラフテンプレート
 * @docs docs/graph/graph-template.md
 */


template <typename G>
struct HeavyLightDecomposition {
 private:
  void dfs_sz(int cur) {
    size[cur] = 1;
    for (auto& dst : g[cur]) {
      if (dst == par[cur]) {
        if (g[cur].size() >= 2 && int(dst) == int(g[cur][0]))
          swap(g[cur][0], g[cur][1]);
        else
          continue;
      }
      depth[dst] = depth[cur] + 1;
      par[dst] = cur;
      dfs_sz(dst);
      size[cur] += size[dst];
      if (size[dst] > size[g[cur][0]]) {
        swap(dst, g[cur][0]);
      }
    }
  }

  void dfs_hld(int cur) {
    down[cur] = id++;
    for (auto dst : g[cur]) {
      if (dst == par[cur]) continue;
      nxt[dst] = (int(dst) == int(g[cur][0]) ? nxt[cur] : int(dst));
      dfs_hld(dst);
    }
    up[cur] = id;
  }

  // [u, v)
  vector<pair<int, int>> ascend(int u, int v) const {
    vector<pair<int, int>> res;
    while (nxt[u] != nxt[v]) {
      res.emplace_back(down[u], down[nxt[u]]);
      u = par[nxt[u]];
    }
    if (u != v) res.emplace_back(down[u], down[v] + 1);
    return res;
  }

  // (u, v]
  vector<pair<int, int>> descend(int u, int v) const {
    if (u == v) return {};
    if (nxt[u] == nxt[v]) return {{down[u] + 1, down[v]}};
    auto res = descend(u, par[nxt[v]]);
    res.emplace_back(down[nxt[v]], down[v]);
    return res;
  }

 public:
  G& g;
  int id;
  vector<int> size, depth, down, up, nxt, par;
  HeavyLightDecomposition(G& _g, int root = 0)
      : g(_g),
        id(0),
        size(g.size(), 0),
        depth(g.size(), 0),
        down(g.size(), -1),
        up(g.size(), -1),
        nxt(g.size(), root),
        par(g.size(), root) {
    dfs_sz(root);
    dfs_hld(root);
  }

  void build(int root) {
    dfs_sz(root);
    dfs_hld(root);
  }

  pair<int, int> idx(int i) const { return make_pair(down[i], up[i]); }

  template <typename F>
  void path_query(int u, int v, bool vertex, const F& f) {
    int l = lca(u, v);
    for (auto&& [a, b] : ascend(u, l)) {
      int s = a + 1, t = b;
      s > t ? f(t, s) : f(s, t);
    }
    if (vertex) f(down[l], down[l] + 1);
    for (auto&& [a, b] : descend(l, v)) {
      int s = a, t = b + 1;
      s > t ? f(t, s) : f(s, t);
    }
  }

  template <typename F>
  void path_noncommutative_query(int u, int v, bool vertex, const F& f) {
    int l = lca(u, v);
    for (auto&& [a, b] : ascend(u, l)) f(a + 1, b);
    if (vertex) f(down[l], down[l] + 1);
    for (auto&& [a, b] : descend(l, v)) f(a, b + 1);
  }

  template <typename F>
  void subtree_query(int u, bool vertex, const F& f) {
    f(down[u] + int(!vertex), up[u]);
  }

  int lca(int a, int b) {
    while (nxt[a] != nxt[b]) {
      if (down[a] < down[b]) swap(a, b);
      a = par[nxt[a]];
    }
    return depth[a] < depth[b] ? a : b;
  }

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

/**
 * @brief Heavy Light Decomposition(重軽分解)
 * @docs docs/tree/heavy-light-decomposition.md
 */


using namespace std;

template <typename T>
struct Namori {
  using G = WeightedGraph<T>;

  int n;
  G g;

  // 部分グラフ
  vector<G> aux;

  // ループ部分の(頂点,辺の重み)
  // loop[i].se は loop[i] と loop[i+1] の間の辺
  vector<pair<int, T>> loop;

  // 頂点の対応関係
  vector<pair<int, int>> mp;

  // HL分解
  vector<HeavyLightDecomposition<G>> hld;

  Namori(int _n = 0) : _uf(_n) { init(_n); }

  void init(int _n) {
    n = _n;
    g.resize(n);
    _uf.data.resize(n);
    fill(begin(_uf.data), end(_uf.data), -1);
    _is_loop.resize(n, false);
    mp.resize(n, make_pair(-1, -1));
  }

  void add_edge(int u, int v, T w = 1) {
    assert(_built == false);
    if (_uf.same(u, v)) {
      _root = u, _adj = v, _w = w;
    } else {
      _uf.unite(u, v);
      g[u].emplace_back(u, v, w);
      g[v].emplace_back(v, u, w);
    }
    if (++_es == n) build();
  }

  void build() {
    if (_built) return;

    _buf.resize(n, -1);
    dfs1(_root, -1);

    for (int c = _adj; c >= 0; c = _buf[c]) {
      loop.emplace_back(c, -1);
      _is_loop[c] = true;
      for (auto& e : g[c]) {
        if (e == _buf[c]) loop.back().second = e.cost;
      }
    }
    assert(loop.back().first == _root);
    loop.back().second = _w;

    _h.resize(n);
    for (auto& [i, _] : loop) dfs2(i, -1);

    fill(begin(_buf), end(_buf), 0);
    for (auto& [i, _] : loop) dfs3(i);

    _uf.data.clear();
    _buf.clear();
    _is_loop.clear();

    aux.resize(loop.size());
    for (int i = 0; i < (int)loop.size(); i++) {
      int k = loop[i].first, j = 0;
      dfs4(k, i, j);
      aux[i].resize(j);

      dfs5(k);
      hld.emplace_back(aux[i]);
    }

    _h.clear();
    _built = true;
  }

  pair<int, int> idx(int i) const { return mp[i]; }

  int root(int i) const { return loop[mp[i].first].first; }

 private:
  // 初期化用の状態変数
  UnionFind _uf;
  vector<int> _buf;
  vector<bool> _is_loop;
  int _root = -1, _adj = -1, _es = 0;
  bool _built = false;
  T _w = 0;
  G _h;

  // parをメモする
  void dfs1(int c, int p) {
    for (auto& d : g[c]) {
      if (d != p) {
        _buf[d] = c;
        dfs1(d, c);
      }
    }
  }

  // _h で有向木を作る
  void dfs2(int c, int p) {
    for (auto& d : g[c]) {
      if (d == p or _is_loop[d]) continue;
      _h[c].emplace_back(c, d, d.cost);
      dfs2(d, c);
    }
  }

  // HLD用に順番替え
  void dfs3(int c) {
    _buf[c] = 1;
    for (auto& d : _h[c]) {
      dfs3(d);
      _buf[c] += _buf[d];
      if (_buf[d] > _buf[_h[c][0]]) {
        swap(_h[c][0], d);
      }
    }
  }

  // 順番をつける
  void dfs4(int c, int i, int& j) {
    mp[c] = make_pair(i, j++);
    for (auto& d : _h[c]) {
      dfs4(d, i, j);
    }
  }

  // 部分グラフを作る
  void dfs5(int c) {
    for (auto& d : _h[c]) {
      dfs5(d);
      auto [i, j] = mp[c];
      auto [_, k] = mp[d];
      aux[i][j].emplace_back(j, k, d.cost);
      // 逆辺も入れたいときはここをオンにする(動くか不明)
      // aux[i][k].emplace_back(k, j, d.cost);
    }
  }
};

/**
 * @brief Functional Graph(なもりグラフ)の分解
 * @docs docs/graph/functional-graph.md
 */




using namespace Nyaan;

void q() {
  ini(N);

  UnionFind uf(N);
  Namori<int> g(N);
  vi deg(N);

  rep(i, N) {
    ini(u, v);
    --u, --v;
    deg[u]++, deg[v]++;
    g.add_edge(u, v);
    uf.unite(u, v);
  }

  if (uf.size(0) != N) die(0);
  trc(g.loop);

  vi freq(6);
  each(d, deg) {
    if (d >= 6) die(0);
    freq[d]++;
  }

  ll ans = 0;
  rep(i, sz(g.loop)) {
    int u = g.loop[i].fi;
    int v = g.loop[(i + 1) % sz(g.loop)].fi;

    freq[deg[u]]--, freq[deg[u] - 1]++;
    freq[deg[v]]--, freq[deg[v] - 1]++;
    if (freq[5] == 0) ans += N - freq[4];
    freq[deg[u]]++, freq[deg[u] - 1]--;
    freq[deg[v]]++, freq[deg[v] - 1]--;
  }
  out(ans);
}

void Nyaan::solve() {
  int t = 1;
  // in(t);
  while (t--) q();
}

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

详细

Test #1:

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

input:

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

output:

10

result:

ok 1 number(s): "10"

Test #2:

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

input:

3
1 3
3 2
2 1

output:

9

result:

ok 1 number(s): "9"

Test #3:

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

input:

2332
1648 909
1676 2122
1644 1981
1106 1131
1785 239
223 618
335 1662
424 1775
889 1684
1589 52
1406 1747
1600 302
790 2056
1742 464
1706 541
1145 779
2316 833
1645 1439
859 438
1337 136
746 1565
436 1730
2079 2145
1583 1940
917 1549
1863 507
1266 367
1890 2230
13 2113
492 2109
120 1122
815 1111
134...

output:

5438224

result:

ok 1 number(s): "5438224"

Test #4:

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

input:

100000
46198 33056
80285 88339
88963 925
43203 66233
13618 35880
19864 76475
90021 73072
3202 63653
41571 83067
22067 98768
10753 16653
32856 85797
3483 2064
46659 9486
23290 82179
97966 23617
81566 7334
81774 76138
10959 75816
93471 12058
97260 66262
85541 78476
67864 87220
8607 52245
38957 67603
7...

output:

10000000000

result:

ok 1 number(s): "10000000000"

Test #5:

score: 0
Accepted
time: 88ms
memory: 41848kb

input:

100000
54772 14057
70680 93042
84913 63248
79360 97774
84190 60881
31137 29439
99037 81117
38579 32074
31206 19912
70774 23067
60717 79586
83847 43306
55351 50174
32566 70092
22736 92279
55916 20029
41571 63309
33143 65579
35033 3869
50038 4275
59533 25348
53092 32698
27604 14678
6802 18226
23173 96...

output:

5017400000

result:

ok 1 number(s): "5017400000"

Test #6:

score: 0
Accepted
time: 28ms
memory: 15632kb

input:

50000
26768 20197
5956 49805
44024 45008
29783 4843
7173 42904
36329 3666
1258 35410
1245 42591
41226 20145
41177 25916
38397 36431
3822 43842
414 31694
28969 33316
47036 42639
5433 1631
26813 16959
17557 18806
45146 10231
26867 24805
4416 45505
44772 32136
26263 17264
43426 20507
26630 4199
9781 89...

output:

94055

result:

ok 1 number(s): "94055"

Test #7:

score: 0
Accepted
time: 24ms
memory: 13440kb

input:

50000
17715 45957
32674 24013
11618 34470
40375 26273
42845 13128
47455 22000
32874 30876
17491 31661
34844 19762
9072 37619
36110 709
268 34175
4270 20690
29515 33513
27912 43001
45583 31336
47547 28782
26922 36614
28304 10847
34444 24189
22768 40293
20188 44360
15389 17250
1073 12635
2478 47836
13...

output:

8051734

result:

ok 1 number(s): "8051734"

Test #8:

score: 0
Accepted
time: 29ms
memory: 14380kb

input:

50000
37455 39098
3151 6272
5096 39790
49906 13081
31622 31592
39120 11585
15349 45507
10760 45706
28023 41368
2327 29590
41990 47577
29250 11516
6810 9343
32121 42608
9553 4051
8790 3141
47114 45057
20325 1150
16016 28877
29716 6021
37777 41072
10612 27253
30459 933
29861 21955
49824 3068
17709 270...

output:

92740

result:

ok 1 number(s): "92740"

Test #9:

score: 0
Accepted
time: 32ms
memory: 13408kb

input:

50000
45571 37975
37274 7584
8276 23675
19496 33814
44225 8331
5709 10694
35506 34740
26328 48062
6085 4427
32680 40409
34161 34842
24200 48199
6831 13256
11261 9734
36423 35721
31037 31766
13399 1942
8062 49588
33071 34851
29051 34723
37974 8227
49945 3621
21863 21924
5665 23743
25046 6591
12174 37...

output:

90984

result:

ok 1 number(s): "90984"

Test #10:

score: 0
Accepted
time: 24ms
memory: 13648kb

input:

50000
35332 25321
25253 26808
1825 13008
42512 12213
42348 46975
15945 10783
37617 25404
12439 31594
28739 24025
21314 26502
3686 22867
19502 47228
15246 7358
35904 4586
5286 15305
28693 13776
44276 7562
27838 5500
40919 52
41478 9675
15676 32415
41353 12056
8301 33451
37563 9459
22381 2826
34996 30...

output:

91952

result:

ok 1 number(s): "91952"

Test #11:

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

input:

100000
5728 9676
70005 86016
43967 6069
25998 15992
25120 46215
71280 3926
50960 33180
76103 91653
39019 53916
31 75541
35484 59797
37091 77981
25183 81534
74314 5751
20419 13475
90063 53064
30839 82393
1073 25122
411 54274
54359 70033
98701 10404
26563 65104
52630 57315
90442 20265
42089 11579
7252...

output:

188242

result:

ok 1 number(s): "188242"

Test #12:

score: 0
Accepted
time: 67ms
memory: 24100kb

input:

100000
55116 18295
96650 80557
4329 50722
1313 76368
37587 25825
78537 18103
406 68671
43420 28393
80913 24601
87683 96542
694 11917
63199 34678
95157 80210
97679 9115
63390 92793
51246 50937
19788 11356
31360 1607
66115 73059
64415 38370
76283 57331
69105 62126
19137 88106
62951 78941
65947 67688
1...

output:

91568

result:

ok 1 number(s): "91568"

Test #13:

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

input:

100000
50883 5999
18393 12126
15334 91408
26392 76076
62384 55943
17693 8898
2559 35077
40756 62967
98202 86230
83949 19932
93158 85510
88663 12650
59846 99904
68413 56736
48738 11679
75726 10843
84088 73780
39309 76757
12359 47501
12053 92575
93789 5454
88405 8870
88404 82684
68204 7531
56193 6902
...

output:

871424097

result:

ok 1 number(s): "871424097"

Test #14:

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

input:

100000
27780 67107
53072 40333
54627 40033
18181 70192
35779 96307
60226 65350
58800 16492
36355 9164
14772 30265
57612 51460
25930 51526
65289 32689
14113 76118
98134 15045
15843 85609
13703 10951
36770 150
71969 59581
34799 82901
59566 35128
2207 24992
63359 83776
5691 40927
90796 76499
86070 8515...

output:

91321

result:

ok 1 number(s): "91321"

Test #15:

score: 0
Accepted
time: 71ms
memory: 24204kb

input:

100000
85137 23757
36555 12897
94235 26110
54855 82870
71976 42445
27780 91475
42701 65921
24419 81582
90491 10676
48481 499
97884 16017
31986 29961
45841 42903
24099 12773
46256 21809
41322 96979
1452 14537
12450 8054
34128 29501
13209 17651
58310 14198
51601 55782
8944 2603
38035 47152
68136 90471...

output:

92070

result:

ok 1 number(s): "92070"

Extra Test:

score: 0
Extra Test Passed