QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#675848#8517. Interesting PathsmaspyAC ✓72ms54288kbC++2319.0kb2024-10-25 19:32:052024-10-25 19:32:08

Judging History

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

  • [2024-10-25 19:32:08]
  • 评测
  • 测评结果:AC
  • 用时:72ms
  • 内存:54288kb
  • [2024-10-25 19:32:05]
  • 提交

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

void solve() {
  LL(N, M);
  Graph<int, 1> G(N);
  G.read_graph(M);
  vc<int> dp1(N), dp2(N);
  vc<int> dp3(M), dp4(M);
  dp1[0] = 1;
  FOR(v, N) {
    if (!dp1[v]) continue;
    for (auto& e: G[v]) {
      dp1[e.to] = 1;
      dp3[e.id] = 1;
    }
  }
  dp2[N - 1] = 1;
  FOR_R(v, N) {
    for (auto& e: G[v]) {
      if (dp2[e.to]) dp2[v] = 1, dp4[e.id] = 1;
    }
  }

  ll a = 0, b = 0;
  FOR(i, N) a += dp1[i] * dp2[i];
  FOR(i, M) b += dp3[i] * dp4[i];

  if (a == 0) return print(0);
  print(b - a + 2);
}

signed main() { solve(); }

詳細信息

Test #1:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

5 3
1 3
2 3
2 5

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 0

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

2 1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #6:

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

input:

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

output:

19

result:

ok 1 number(s): "19"

Test #7:

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

input:

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

output:

21

result:

ok 1 number(s): "21"

Test #8:

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

input:

16 19
5 10
10 13
12 13
15 16
7 11
1 6
14 15
3 4
6 8
11 12
4 5
13 14
5 7
9 12
1 2
2 4
5 12
8 9
1 3

output:

5

result:

ok 1 number(s): "5"

Test #9:

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

input:

14 91
3 13
1 9
4 12
1 12
11 14
8 10
9 14
5 11
9 11
1 11
1 2
10 14
1 7
4 9
2 10
13 14
2 6
4 6
12 13
5 13
2 8
1 14
9 10
3 8
2 11
5 14
7 9
6 10
7 11
1 10
12 14
3 14
3 7
7 8
1 13
10 11
2 14
6 14
8 9
6 9
2 4
4 7
4 14
9 13
2 7
6 12
5 7
4 5
2 9
11 12
6 8
8 11
4 8
7 14
7 12
5 12
2 5
11 13
6 7
6 11
7 13
3 4
...

output:

79

result:

ok 1 number(s): "79"

Test #10:

score: 0
Accepted
time: 7ms
memory: 15124kb

input:

1000000 0

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 39ms
memory: 43048kb

input:

10000 1000000
3186 5896
193 9783
2762 3101
2793 5391
2587 9231
2991 6139
317 448
361 5290
7372 7580
279 2589
5476 7584
2829 3375
3785 8539
5898 7644
460 2025
2029 6959
1249 8686
1787 5348
840 7031
9515 9862
6122 9224
3911 5359
725 4062
985 5179
3337 4188
6961 8345
5325 6480
8308 9019
7827 9054
759 3...

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 63ms
memory: 54056kb

input:

1000000 1000000
227867 264986
543264 885751
368699 709020
126827 786083
15773 700372
582092 653193
597763 662903
24964 669822
118877 700066
650866 776787
264084 934355
104858 656657
393038 691935
254875 794624
349005 722140
77011 854592
264566 829978
395038 833643
180017 193646
28588 147277
71335 79...

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 56ms
memory: 53932kb

input:

1000000 1000000
277718 460482
147752 592243
672428 950124
290176 395254
169855 591213
23051 603108
683561 886805
369178 558263
15523 306646
851733 898093
16252 953612
195928 796663
298711 941197
807239 939884
477390 577792
177636 375148
199307 279986
171470 388424
864738 896318
520095 685892
281955 ...

output:

987489

result:

ok 1 number(s): "987489"

Test #14:

score: 0
Accepted
time: 30ms
memory: 34460kb

input:

1000000 500000
220011 331608
383898 452284
478455 598602
535465 835096
34781 509172
284635 653292
553793 686935
595558 905694
106231 182420
72160 205103
435467 474167
133438 709831
447900 993899
311233 441916
30052 897382
34200 490411
24306 365889
346868 769417
163206 392108
340962 818759
699298 730...

output:

442134

result:

ok 1 number(s): "442134"

Test #15:

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

input:

10000 1000000
769 5111
2621 5295
616 5384
603 9873
257 7962
4616 5977
4420 7963
1225 7007
5292 7230
6869 8661
5669 5714
7618 9925
2384 2393
1029 7575
3713 6965
1131 7793
6479 9949
5650 5880
6640 6735
4012 7870
6937 8667
3173 8439
1618 7794
1166 3266
4671 5333
3778 5189
1386 8839
1577 6482
764 7866
2...

output:

893098

result:

ok 1 number(s): "893098"

Test #16:

score: 0
Accepted
time: 53ms
memory: 42732kb

input:

25000 1000000
3286 13917
7601 14129
18179 21682
12738 14859
2310 11787
13237 13313
1403 20530
2019 12776
7246 21258
109 4285
1250 5654
3281 16015
4357 7111
509 5915
8595 11893
15252 17559
5074 7653
5468 21483
4532 20843
9827 24533
5902 23960
2056 5538
11183 12864
1648 9275
19962 23304
12806 18024
41...

output:

687486

result:

ok 1 number(s): "687486"

Test #17:

score: 0
Accepted
time: 56ms
memory: 53828kb

input:

1000000 1000000
145889 828965
101891 872944
306461 891194
479634 562124
460093 702806
434097 687914
868462 943584
522148 811696
202648 321281
413792 709955
9764 601279
257576 742047
310620 793868
444655 595009
47265 57177
277171 641024
281005 694629
508946 736418
264412 927342
33742 591190
274183 92...

output:

171017

result:

ok 1 number(s): "171017"

Test #18:

score: 0
Accepted
time: 72ms
memory: 54052kb

input:

1000000 1000000
987682 991819
630763 967194
682365 816105
15669 988580
649157 744816
777657 787054
515972 839941
428069 860906
127350 850842
91250 505765
522849 651379
194742 204624
71459 470879
181532 208277
330718 442774
486299 868372
186798 859668
474733 619379
997653 998142
758371 812576
407121 ...

output:

500000

result:

ok 1 number(s): "500000"

Test #19:

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

input:

1000000 999943
53949 54134
897043 897608
142382 142409
739225 740088
316622 317223
612614 612628
962920 963039
326871 327062
865159 865823
436490 437418
543160 544108
337346 337592
964581 964673
79918 80229
302781 302829
203405 203527
152922 152944
131508 132109
938757 939268
266846 266862
492730 49...

output:

3954

result:

ok 1 number(s): "3954"

Test #20:

score: 0
Accepted
time: 66ms
memory: 48336kb

input:

500251 1000000
9947 11131
89269 90762
138209 138334
35780 36236
324719 324911
155905 156017
302265 302981
230612 230795
179197 180540
413336 413824
382765 383223
242408 244400
186393 187212
323869 323912
471208 472286
486731 486805
69468 71026
439179 439816
231003 231616
390438 390831
445002 445640
...

output:

499751

result:

ok 1 number(s): "499751"

Test #21:

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

input:

963427 1000000
756122 756156
561525 561536
235985 236007
613316 613342
870234 870247
851771 851828
455702 455708
880636 880643
75192 75198
420611 420618
89553 89606
800364 800366
6742 6767
455571 455594
732558 732565
110656 110680
779653 779657
636588 636602
740997 741035
216394 216434
77384 77385
1...

output:

36575

result:

ok 1 number(s): "36575"

Test #22:

score: 0
Accepted
time: 54ms
memory: 53900kb

input:

1000000 1000000
558447 558448
407630 407633
213948 213949
198910 198912
698681 698682
707290 707292
14135 14137
40970 40978
463970 463971
951953 951956
535948 535949
290406 290410
979508 979509
358721 358722
727174 727176
546791 546792
858586 858589
570708 570709
678280 678283
440169 440170
577316 5...

output:

125011

result:

ok 1 number(s): "125011"

Test #23:

score: 0
Accepted
time: 66ms
memory: 54100kb

input:

1000000 1000000
86248 86251
532234 532235
495597 495599
438265 438267
968894 968895
472438 472440
999816 999818
295216 295217
874654 874655
323449 323454
119717 119718
48635 48636
241458 241460
323449 323450
94703 94706
951489 951490
291403 291404
875556 875557
49412 49414
209004 209005
809812 80981...

output:

250001

result:

ok 1 number(s): "250001"

Test #24:

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

input:

1000000 999999
401523 401524
707079 707080
520426 520427
129319 129320
730775 730776
691407 691408
471148 471149
189429 189430
424401 424402
707207 707208
154396 154397
759908 759909
412175 412176
805859 805860
909958 909959
150392 150393
907342 907343
417376 417377
601790 601791
724403 724404
35205...

output:

1

result:

ok 1 number(s): "1"

Test #25:

score: 0
Accepted
time: 45ms
memory: 42236kb

input:

1415 1000000
267 519
42 835
306 842
886 1412
700 1199
958 1293
92 487
193 1037
544 590
810 1363
229 607
206 1286
608 642
281 1224
720 1027
113 787
118 374
627 1097
175 1199
183 1121
18 1406
365 503
600 1202
287 981
180 398
870 1016
409 1155
864 1307
712 1309
65 582
39 60
5 541
787 1337
736 958
1202 ...

output:

998587

result:

ok 1 number(s): "998587"

Test #26:

score: 0
Accepted
time: 47ms
memory: 42376kb

input:

1414 998991
397 429
866 1016
409 1101
240 454
267 938
9 970
94 109
473 1311
767 1155
252 370
182 613
139 955
116 321
1066 1144
1011 1122
1247 1282
433 809
255 953
1313 1333
10 950
1058 1208
494 600
349 369
537 1012
123 1118
149 539
47 321
536 1096
223 875
547 562
26 317
1203 1245
956 1263
704 1072
2...

output:

997579

result:

ok 1 number(s): "997579"

Test #27:

score: 0
Accepted
time: 53ms
memory: 54276kb

input:

1000000 998991
234789 795210
91941 754122
747677 896007
344635 430364
599439 705004
120147 586537
73552 86709
209503 816560
436215 819408
600756 817215
301264 704189
163900 945551
115787 269217
37272 289783
200626 351053
277178 571637
235083 718740
82476 892729
413061 807263
366100 806564
195698 560...

output:

997579

result:

ok 1 number(s): "997579"

Test #28:

score: 0
Accepted
time: 64ms
memory: 54132kb

input:

1000000 1000000
368406 854062
619199 859849
228408 362095
513960 877053
801742 884339
222736 721090
41570 865619
800334 816559
63571 510218
159258 192195
840210 957865
743127 868555
207780 239075
138464 208672
105314 792016
391815 572706
43405 60814
233729 555289
661063 806616
645615 837773
323700 9...

output:

998587

result:

ok 1 number(s): "998587"

Extra Test:

score: 0
Extra Test Passed