QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108201#6329. Colorful GraphmaspyAC ✓525ms7132kbC++2324.4kb2023-05-23 21:20:512023-05-23 21:20:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 21:20:54]
  • 评测
  • 测评结果:AC
  • 用时:525ms
  • 内存:7132kb
  • [2023-05-23 21:20:51]
  • 提交

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

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

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  assert(!que.empty());
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  assert(!que.empty());
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.write(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

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

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

  template <class T>
  static auto check(...) -> std::false_type;
};

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

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <typename T,
            typename enable_if<has_read<T>::value>::type * = nullptr>
  inline bool read_single(T &x) {
    x.read();
    return true;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <size_t N = 0, typename T>
  void read_single_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
      auto &x = std::get<N>(t);
      read_single(x);
      read_single_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool read_single(tuple<T...> &tpl) {
    read_single_tuple(tpl);
    return true;
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <typename T,
            typename enable_if<has_write<T>::value>::type * = nullptr>
  inline void write(T x) {
    x.write();
  }
  template <class T>
  void write(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <size_t N = 0, typename T>
  void write_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
      if constexpr (N > 0) { write(' '); }
      const auto x = std::get<N>(t);
      write(x);
      write_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool write(tuple<T...> tpl) {
    write_tuple(tpl);
    return true;
  }
  template <class T, size_t S>
  void write(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if (val < 0) {
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if (negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  printer.write(head);
  if (sizeof...(Tail)) printer.write(' ');
  print(forward<Tail>(tail)...);
}

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"

#line 2 "library/graph/base.hpp"

template <typename T>
struct Edge {
  int frm, to;
  T cost;
  int id;
};

template <typename T = int, bool directed = false>
struct Graph {
  int N, M;
  using cost_type = T;
  using edge_type = Edge<T>;
  vector<edge_type> edges;
  vector<int> indptr;
  vector<edge_type> csr_edges;
  vc<int> vc_deg, vc_indeg, vc_outdeg;
  bool prepared;

  class OutgoingEdges {
  public:
    OutgoingEdges(const Graph* G, int l, int r) : G(G), l(l), r(r) {}

    const edge_type* begin() const {
      if (l == r) { return 0; }
      return &G->csr_edges[l];
    }

    const edge_type* end() const {
      if (l == r) { return 0; }
      return &G->csr_edges[r];
    }

  private:
    const Graph* G;
    int l, r;
  };

  bool is_prepared() { return prepared; }
  constexpr bool is_directed() { return directed; }

  Graph() : N(0), M(0), prepared(0) {}
  Graph(int N) : N(N), M(0), prepared(0) {}

  void build(int n) {
    N = n, M = 0;
    prepared = 0;
    edges.clear();
    indptr.clear();
    csr_edges.clear();
    vc_deg.clear();
    vc_indeg.clear();
    vc_outdeg.clear();
  }

  void add(int frm, int to, T cost = 1, int i = -1) {
    assert(!prepared);
    assert(0 <= frm && 0 <= to && to < N);
    if (i == -1) i = M;
    auto e = edge_type({frm, to, cost, i});
    edges.eb(e);
    ++M;
  }

  // wt, off
  void read_tree(bool wt = false, int off = 1) { read_graph(N - 1, wt, off); }

  void read_graph(int M, bool wt = false, int off = 1) {
    for (int m = 0; m < M; ++m) {
      INT(a, b);
      a -= off, b -= off;
      if (!wt) {
        add(a, b);
      } else {
        T c;
        read(c);
        add(a, b, c);
      }
    }
    build();
  }

  void build() {
    assert(!prepared);
    prepared = true;
    indptr.assign(N + 1, 0);
    for (auto&& e: edges) {
      indptr[e.frm + 1]++;
      if (!directed) indptr[e.to + 1]++;
    }
    for (int v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; }
    auto counter = indptr;
    csr_edges.resize(indptr.back() + 1);
    for (auto&& e: edges) {
      csr_edges[counter[e.frm]++] = e;
      if (!directed)
        csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id});
    }
  }

  OutgoingEdges operator[](int v) const {
    assert(prepared);
    return {this, indptr[v], indptr[v + 1]};
  }

  vc<int> deg_array() {
    if (vc_deg.empty()) calc_deg();
    return vc_deg;
  }

  pair<vc<int>, vc<int>> deg_array_inout() {
    if (vc_indeg.empty()) calc_deg_inout();
    return {vc_indeg, vc_outdeg};
  }

  int deg(int v) {
    if (vc_deg.empty()) calc_deg();
    return vc_deg[v];
  }

  int in_deg(int v) {
    if (vc_indeg.empty()) calc_deg_inout();
    return vc_indeg[v];
  }

  int out_deg(int v) {
    if (vc_outdeg.empty()) calc_deg_inout();
    return vc_outdeg[v];
  }

  void debug() {
    print("Graph");
    if (!prepared) {
      print("frm to cost id");
      for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id);
    } else {
      print("indptr", indptr);
      print("frm to cost id");
      FOR(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id);
    }
  }

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

  // G における頂点 V[i] が、新しいグラフで i になるようにする
  // {G, es}
  pair<Graph<T, directed>, vc<int>> rearrange(vc<int> V) {
    if (len(new_idx) != N) new_idx.assign(N, -1);
    if (len(used_e) != M) used_e.assign(M, 0);
    int n = len(V);
    FOR(i, n) new_idx[V[i]] = i;
    Graph<T, directed> G(n);
    vc<int> es;
    FOR(i, n) {
      for (auto&& e: (*this)[V[i]]) {
        if (used_e[e.id]) continue;
        int a = e.frm, b = e.to;
        if (new_idx[a] != -1 && new_idx[b] != -1) {
          used_e[e.id] = 1;
          G.add(new_idx[a], new_idx[b], e.cost);
          es.eb(e.id);
        }
      }
    }
    FOR(i, n) new_idx[V[i]] = -1;
    for (auto&& eid: es) used_e[eid] = 0;
    G.build();
    return {G, es};
  }

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 3 "library/graph/strongly_connected_component.hpp"

template <typename Graph>
pair<int, vc<int>> strongly_connected_component(Graph& G) {
  assert(G.is_directed());
  assert(G.is_prepared());
  int N = G.N;
  int C = 0;
  vc<int> comp(N);
  vc<int> low(N);
  vc<int> ord(N, -1);
  vc<int> visited;
  int now = 0;

  auto dfs = [&](auto self, int v) -> void {
    low[v] = now;
    ord[v] = now;
    ++now;
    visited.eb(v);
    for (auto&& [frm, to, cost, id]: G[v]) {
      if (ord[to] == -1) {
        self(self, to);
        chmin(low[v], low[to]);
      } else {
        chmin(low[v], ord[to]);
      }
    }
    if (low[v] == ord[v]) {
      while (1) {
        int u = visited.back();
        visited.pop_back();
        ord[u] = N;
        comp[u] = C;
        if (u == v) break;
      }
      ++C;
    }
  };
  FOR(v, N) {
    if (ord[v] == -1) dfs(dfs, v);
  }
  FOR(v, N) comp[v] = C - 1 - comp[v];
  return {C, comp};
}

template <typename GT>
Graph<int, 1> scc_dag(GT& G, int C, vc<int>& comp) {
  Graph<int, 1> DAG(C);
  vvc<int> edges(C);
  for (auto&& e: G.edges) {
    int x = comp[e.frm], y = comp[e.to];
    if (x == y) continue;
    edges[x].eb(y);
  }
  FOR(c, C) {
    UNIQUE(edges[c]);
    for (auto&& to: edges[c]) DAG.add(c, to);
  }
  DAG.build();
  return DAG;
}
#line 1 "library/flow/maxflow.hpp"
template <typename Cap>
struct MaxFlowGraph {
  struct Edge {
    int to, rev;
    Cap cap;
    Cap flow = 0;
  };

  int N;
  vc<tuple<int, int, Cap, Cap>> dat;
  vc<int> prog, level;
  vc<int> que;
  vc<Edge> edges;
  vc<int> indptr;
  Cap flow_ans;
  bool calculated;
  bool is_prepared;

  MaxFlowGraph(int N) : N(N), calculated(0), is_prepared(0) {}

  void add(int frm, int to, Cap cap, Cap rev_cap = 0) {
    assert(0 <= frm && frm < N);
    assert(0 <= to && to < N);
    assert(Cap(0) <= cap);
    if (frm == to) return;
    dat.eb(frm, to, cap, rev_cap);
  }

  void build() {
    assert(!is_prepared);
    int M = len(dat);
    is_prepared = 1;
    indptr.assign(N, 0);
    for (auto&& [a, b, c, d]: dat) indptr[a]++, indptr[b]++;
    indptr = cumsum<int>(indptr);
    vc<int> nxt_idx = indptr;
    edges.resize(2 * M);
    for (auto&& [a, b, c, d]: dat) {
      int p = nxt_idx[a]++;
      int q = nxt_idx[b]++;
      edges[p] = Edge{b, q, c};
      edges[q] = Edge{a, p, d};
    }
  }

  vc<tuple<int, int, Cap>> get_flow_edges() {
    vc<tuple<int, int, Cap>> res;
    FOR(frm, N) {
      FOR(k, indptr[frm], indptr[frm + 1]) {
        auto& e = edges[k];
        if (e.flow <= 0) continue;
        res.eb(frm, e.to, e.flow);
      }
    }
    return res;
  }

  Cap flow(int source, int sink) {
    assert(is_prepared);
    if (calculated) return flow_ans;
    calculated = true;
    flow_ans = 0;
    while (set_level(source, sink)) {
      prog = indptr;
      while (1) {
        Cap x = flow_dfs(source, sink, infty<Cap>);
        if (x == 0) break;
        flow_ans += x;
        chmin(flow_ans, infty<Cap>);
        if (flow_ans == infty<Cap>) return flow_ans;
      }
    }
    return flow_ans;
  }

  // 最小カットの値および、カットを表す 01 列を返す
  pair<Cap, vc<int>> cut(int source, int sink) {
    Cap f = flow(source, sink);
    vc<int> res(N);
    FOR(v, N) res[v] = (level[v] >= 0 ? 0 : 1);
    return {f, res};
  }

private:
  bool set_level(int source, int sink) {
    que.resize(N);
    level.assign(N, -1);
    level[source] = 0;
    int l = 0, r = 0;
    que[r++] = source;
    while (l < r) {
      int v = que[l++];
      FOR(k, indptr[v], indptr[v + 1]) {
        auto& e = edges[k];
        if (e.cap > 0 && level[e.to] == -1) {
          level[e.to] = level[v] + 1;
          if (e.to == sink) return true;
          que[r++] = e.to;
        }
      }
    }
    return false;
  }

  Cap flow_dfs(int v, int sink, Cap lim) {
    if (v == sink) return lim;
    Cap res = 0;
    for (int& i = prog[v]; i < indptr[v + 1]; ++i) {
      auto& e = edges[i];
      if (e.cap > 0 && level[e.to] == level[v] + 1) {
        Cap a = flow_dfs(e.to, sink, min(lim, e.cap));
        if (a > 0) {
          e.cap -= a, e.flow += a;
          edges[e.rev].cap += a, edges[e.rev].flow -= a;
          res += a;
          lim -= a;
          if (lim == 0) break;
        }
      }
    }
    return res;
  }
};
#line 2 "library/ds/unionfind/unionfind.hpp"

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

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

  void reset() { build(n); }

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

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

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

// 各頂点の色をかえす。各色はひとつのパス上にあるようにする
template <typename DAG>
vc<int> dag_path_cover(DAG& G) {
  assert(G.is_directed());
  for (auto&& e: G.edges) assert(e.frm < e.to);

  int N = G.N;
  MaxFlowGraph<int> F(2 * N + 2);
  int source = 2 * N, sink = 2 * N + 1;
  FOR(v, N) {
    F.add(source, 2 * v + 1, 1);
    F.add(2 * v + 0, sink, 1);
    F.add(2 * v + 0, 2 * v + 1, infty<int>);
  }
  for (auto&& e: G.edges) F.add(2 * e.frm + 1, 2 * e.to + 0, infty<int>);
  F.build();

  int flow = F.flow(source, sink);

  vvc<pair<int, int>> flow_edges(N + N + 2);
  for (auto&& [a, b, c]: F.get_flow_edges()) { flow_edges[a].eb(b, c); }

  UnionFind uf(N);
  for (auto&& [a, f]: flow_edges[source]) {
    assert(f == 1);
    int b = a;
    while (1) {
      auto [to, x] = POP(flow_edges[b]);
      x -= 1;
      if (x > 0) flow_edges[b].eb(to, x);
      if (to == sink) break;
      b = to;
    }
    uf.merge(a / 2, b / 2);
  }

  vc<int> ANS(N, -1);
  int p = 0;
  FOR(v, N) if (uf[v] == v) ANS[v] = p++;
  FOR(v, N) if (uf[v] != v) ANS[v] = ANS[uf[v]];
  return ANS;
};
#line 6 "main.cpp"

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

  auto [nc, comp] = strongly_connected_component(G);
  auto DAG = scc_dag(G, nc, comp);
  auto color = dag_path_cover(DAG);

  vc<int> ANS(N);
  FOR(v, N) ANS[v] = color[comp[v]] + 1;
  print(ANS);
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1 1 1 2 1

result:

ok AC

Test #2:

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

input:

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

output:

2 2 1 1 1

result:

ok AC

Test #3:

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

input:

8 6
6 1
3 4
3 6
2 3
4 1
6 4

output:

4 4 4 4 3 4 2 1

result:

ok AC

Test #4:

score: 0
Accepted
time: 324ms
memory: 6816kb

input:

7000 6999
4365 4296
2980 3141
6820 4995
4781 24
2416 5844
2940 2675
3293 2163
3853 5356
262 6706
1985 1497
5241 3803
353 1624
5838 4708
5452 3019
2029 6161
3849 4219
1095 1453
4268 4567
1184 1857
2911 3977
1662 2751
6353 6496
2002 6628
1407 4623
425 1331
4445 4277
1259 3165
4994 1044
2756 5788
5496 ...

output:

1750 1658 1327 1565 1748 1749 1748 1366 1110 1506 1750 1750 1747 1750 1520 1746 517 1745 1061 25 1258 586 1748 1499 1663 1744 1743 1745 1405 1742 1172 1199 1741 1740 1358 1359 286 1739 1748 1738 1526 1158 1737 535 1736 688 1735 1748 1734 1733 890 1732 1293 1748 1648 187 1750 1731 1031 1730 1193 1748...

result:

ok AC

Test #5:

score: 0
Accepted
time: 525ms
memory: 6748kb

input:

7000 6999
4832 1603
5984 6985
5355 3687
6007 2170
5984 3486
3267 2189
538 2123
4343 4553
5855 6168
5984 257
4239 2304
5984 2063
3298 1869
5984 6353
5984 2018
5984 5387
5984 3382
3164 3978
2690 2816
4810 2638
5984 3773
5984 1634
5984 2786
5984 3671
5984 5140
2943 5721
5984 414
1105 4060
3093 796
5984...

output:

2294 2294 619 466 1724 2294 887 672 2294 2294 2294 2294 2294 1275 2294 2333 2294 2294 2294 2331 2332 1714 2096 1233 2294 2294 849 1897 783 1569 1665 2294 2294 2294 2331 2330 1372 2294 117 135 2329 238 1188 2328 1847 2327 21 2326 2325 1574 18 1534 2304 204 1812 2294 2324 2323 2322 2321 2294 2294 2320...

result:

ok AC

Test #6:

score: 0
Accepted
time: 517ms
memory: 6832kb

input:

7000 6999
1649 5337
1701 3344
4394 2172
3330 39
5932 1141
5381 5340
5453 3300
125 2172
6810 5263
804 2172
6635 2172
676 4740
3015 1183
1710 5769
611 5915
3419 1581
2094 2172
4508 2172
6604 2433
6113 1466
1604 696
1518 1123
1287 2940
4825 2172
5130 4524
2693 2172
106 2172
5157 2172
3693 2172
5198 217...

output:

2333 2332 464 319 2256 2331 165 1084 1720 2330 1209 2329 2328 1456 1755 529 2327 385 1158 1690 1683 2326 2325 1446 1840 266 1643 413 2324 2323 1792 2322 1334 1621 1410 2321 1970 421 94 2320 2126 2073 1741 2319 1998 1177 1705 303 2318 2298 377 2317 1672 1538 1695 323 2043 2316 583 2329 2315 2282 2314...

result:

ok AC

Test #7:

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

input:

7000 6999
2896 6321
881 2623
5058 2623
4833 2623
4669 2623
4781 5007
1447 2623
4781 4768
4781 3834
2758 4792
797 5055
3784 2623
4781 5510
6606 3040
597 3459
4136 2037
1291 3989
4781 837
4781 4379
5637 2053
1642 2665
4781 4664
4781 952
4924 2511
4781 4201
4781 2352
4781 5362
3901 197
137 2623
2706 19...

output:

1750 1750 1750 1750 1750 1750 1750 1749 354 1748 1750 1750 1750 1750 1750 1443 1548 1750 1750 1747 1345 1750 795 607 1367 1504 1428 1007 1746 1745 1750 1744 1750 1750 1750 1750 1536 226 1750 699 1750 1750 879 1750 1743 1750 1742 1750 1741 1750 1750 1750 1740 1739 1750 1738 1750 1750 783 1750 1737 17...

result:

ok AC

Test #8:

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

input:

6999 6998
1269 3969
1269 2429
1269 2609
1269 2515
1269 6166
1269 6614
3108 1269
2105 1269
4670 1269
578 1269
4661 1269
1421 1269
2576 1269
6152 1269
1269 6636
3011 1269
305 1269
5189 1269
1683 1269
6861 1269
1269 5798
1499 1269
282 1269
914 1269
80 1269
677 1269
701 1269
1269 359
6521 1269
1269 1754...

output:

3499 3498 3497 3496 1073 3495 3494 2667 1045 3245 3304 2946 3493 434 3492 3491 3490 976 3489 3488 125 3487 3486 2692 3485 3484 3483 3482 3481 1675 3480 1067 3479 3478 3194 3477 1614 459 3476 515 971 3475 3474 1204 3088 3473 3472 3471 3470 3469 2522 1552 3493 3468 263 2395 3467 3466 3465 3464 3463 57...

result:

ok AC

Test #9:

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

input:

7000 0

output:

7000 6999 6998 6997 6996 6995 6994 6993 6992 6991 6990 6989 6988 6987 6986 6985 6984 6983 6982 6981 6980 6979 6978 6977 6976 6975 6974 6973 6972 6971 6970 6969 6968 6967 6966 6965 6964 6963 6962 6961 6960 6959 6958 6957 6956 6955 6954 6953 6952 6951 6950 6949 6948 6947 6946 6945 6944 6943 6942 6941 ...

result:

ok AC

Test #10:

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

input:

7000 6999
3138 1903
3285 5919
6182 1430
1164 961
1577 6445
1390 3384
935 5723
6614 6387
4799 2877
3915 5128
5366 5455
2287 3941
2053 2326
4022 6993
488 2922
4327 4701
4674 3221
1666 4773
4356 3232
3888 937
4318 6942
577 1299
4491 1938
5154 1254
790 5532
4286 5478
2918 6725
2853 304
2554 5207
5140 77...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok AC

Test #11:

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

input:

7000 6999
33 3147
5877 4807
3116 4168
1651 2456
624 1740
6440 3058
6414 489
1023 2523
706 93
5523 598
4211 6063
3570 6840
6566 2971
6614 1907
5893 4389
4022 2527
5096 2345
4682 2134
188 5597
695 4285
1344 3832
3534 879
6574 6252
3759 3444
2167 85
5630 6600
3158 4404
6389 689
4871 6719
4295 6008
3437...

output:

28 22 2 2 32 32 2 5 2 2 2 2 2 71 2 5 2 31 2 2 52 2 22 2 2 2 2 2 2 2 2 2 70 2 2 5 65 44 2 2 2 32 56 2 69 2 52 2 2 5 2 2 2 2 2 5 2 2 2 24 52 65 65 2 2 2 2 1 22 2 7 22 2 2 32 2 19 1 22 2 28 45 2 2 59 17 2 2 45 2 22 2 2 2 2 41 68 2 59 2 2 2 2 44 2 2 31 2 2 19 2 2 2 28 44 2 22 2 2 2 2 19 1 2 44 2 2 2 2 2...

result:

ok AC

Test #12:

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

input:

7000 6999
1247 5150
3318 2013
5686 1615
6145 6521
5717 94
2787 3443
2648 4875
5332 5934
1897 1651
4640 2183
1750 6964
148 5228
745 2814
474 1165
496 6735
180 3412
2723 3374
6200 4361
497 5328
1928 5998
5648 1261
5090 4723
1715 706
2499 897
6569 6204
6039 2787
2882 5044
5767 4256
975 1877
1857 4453
6...

output:

1 274 1 213 1 1 203 1 57 1 259 16 201 1 1 200 1 1 1 1 1 1 1 1 1 1 62 1 145 273 1 1 1 1 1 1 80 1 160 1 1 1 60 1 1 213 1 1 1 99 43 272 1 1 1 1 1 226 259 1 213 191 1 1 1 16 1 1 255 171 1 7 145 1 1 1 1 1 271 207 1 1 1 1 1 213 1 1 1 1 255 1 1 1 244 1 1 1 1 1 99 1 1 255 213 1 1 60 1 200 62 1 1 171 1 61 1 ...

result:

ok AC

Test #13:

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

input:

7000 6999
2349 199
5295 2831
6143 2006
3212 3198
6956 3807
732 4838
5069 1027
5744 3479
6 5301
5687 4452
4201 1151
1353 4884
548 3506
6094 4799
4950 6939
5234 817
652 1314
979 6984
5771 1851
398 1322
2294 4298
847 3929
6833 183
2904 6745
4797 3874
94 315
4282 582
6591 5037
962 147
799 908
2593 5547
...

output:

1 1049 945 1 1 696 170 485 384 791 665 1 16 702 95 1 382 374 1048 640 52 1 1 1047 204 1 1 1046 599 1 742 281 309 786 1 605 1 39 428 814 116 1 657 286 1 1045 58 1 1 1044 205 584 1043 1042 89 1041 791 636 1040 291 1 1 773 1 1 161 945 676 958 674 1 1 1 1 16 1 342 1 673 880 1 1 1 189 1039 605 1 189 1 77...

result:

ok AC

Test #14:

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

input:

7000 6999
3409 1629
2076 6412
4997 1078
6320 626
4501 1104
4173 1774
5507 2375
2299 5115
4321 127
1192 6635
1909 3398
2972 499
862 5024
421 2931
861 1536
902 3813
659 4514
1843 3035
3669 1228
1724 1880
34 706
133 3468
6116 585
5073 1461
5667 3405
715 4834
6915 3007
1736 6108
3264 2870
2393 6474
2108...

output:

1804 15 2618 972 15 2617 1618 15 752 2616 1065 2615 15 2614 2613 198 2483 15 1620 811 15 2612 15 935 2611 15 2610 2609 2608 2607 15 2606 15 2605 2522 1686 624 1148 2604 1539 402 1296 2323 2043 15 2529 2327 2110 2603 255 1999 1263 15 515 15 166 1734 99 2602 2601 368 15 1718 2600 237 2599 2494 2598 31...

result:

ok AC

Test #15:

score: 0
Accepted
time: 9ms
memory: 6048kb

input:

7000 7000
2048 5882
6801 2408
3225 2608
1441 5079
497 6253
557 5589
2535 6257
4800 2595
4713 1286
4759 6636
4303 4296
6195 2048
6994 2987
1249 3044
1036 10
6472 2076
1996 1086
1279 1486
6100 369
4797 3437
2493 4576
2944 5601
197 5582
5488 5035
4023 659
2651 5024
2257 5710
1001 3941
446 4815
687 702
...

output:

3009 3008 3007 3006 3005 3003 1002 3000 2999 2390 2997 2475 2993 1107 1053 718 2976 2975 2115 360 1911 2974 2183 654 2973 2802 2470 948 2969 1631 2962 2961 2380 1385 1378 2959 2958 2957 1537 2956 2955 2954 2953 2020 1883 2952 2951 2260 1564 2695 2949 2793 2948 1138 2946 1490 2945 841 2943 2389 2942 ...

result:

ok AC

Test #16:

score: 0
Accepted
time: 8ms
memory: 6112kb

input:

6993 7000
6927 2941
6385 1428
6914 2553
2474 4268
2068 1640
2298 6960
6201 1806
4912 59
4407 5504
1595 6868
6378 2515
3713 3724
2995 2589
2314 2932
4042 431
6322 4178
5947 6850
6192 735
3802 1043
4982 1575
311 6496
5006 3191
6473 3084
2387 4706
6632 5901
5113 3066
5248 1274
5671 717
1311 4261
1960 3...

output:

1182 1744 2990 428 1105 2989 480 2988 1134 2987 2986 2305 379 2977 2976 2971 23 2970 1342 1591 2967 2966 2965 498 1717 2007 2033 1613 173 2022 2962 2961 2960 2117 2959 2958 2929 807 2957 1613 2949 2948 1133 941 2936 195 1675 2947 2946 836 2945 1309 2938 2567 2937 2936 2935 2954 79 2934 2954 1111 263...

result:

ok AC

Test #17:

score: 0
Accepted
time: 4ms
memory: 5968kb

input:

6930 7000
3746 2945
3523 6758
4109 1106
2732 5415
2423 844
3702 6309
6503 5362
5997 6294
5688 1396
4842 1764
4780 4521
1254 826
37 4653
2138 2358
6345 1223
1385 2341
5261 5867
4815 2918
4209 696
4235 2314
3680 2919
5605 5155
6643 3391
2691 1418
6289 2093
1970 1804
828 5237
4025 1111
1164 5519
5889 2...

output:

2927 2925 2924 300 1753 2705 2919 2918 389 2917 2182 2372 399 2916 2915 2912 2911 1463 1308 499 1849 2910 987 1413 2909 2908 107 2907 1578 2905 2653 2903 2902 119 766 980 2901 2900 2860 2899 2898 2897 1830 2896 2895 475 2894 522 1666 882 356 2890 2056 2889 2880 2879 2877 2876 2546 2875 2874 2873 272...

result:

ok AC

Test #18:

score: 0
Accepted
time: 10ms
memory: 5636kb

input:

6300 7000
5921 5466
723 5843
1084 3134
3865 5742
5492 2885
328 4408
6055 4074
3702 2240
1342 2353
295 734
553 48
4454 2980
1248 4460
5023 19
2784 441
105 844
6048 1773
4840 5260
3910 1292
5578 2864
4978 3116
6182 4962
2575 1661
5030 435
5861 4709
5033 358
1746 5816
5877 3921
2678 5679
1784 33
207 59...

output:

2058 2392 242 2391 1824 2390 2389 9 2388 2146 2387 2386 2385 2384 2383 2382 2381 2375 2217 2042 2374 2373 725 2372 1348 2371 635 2370 185 8 1197 1208 216 2368 2367 2366 87 1670 1001 2051 1040 289 1232 1970 2333 2365 685 1176 2364 1287 508 504 2359 2366 1464 2356 2355 1127 825 2351 327 1232 2350 2349...

result:

ok AC

Test #19:

score: 0
Accepted
time: 3ms
memory: 4220kb

input:

2800 7000
218 2670
1436 2268
38 2781
55 783
549 1627
660 1609
2268 2645
1376 1395
2747 71
785 1451
1096 2633
2655 2557
1569 307
16 56
1993 2751
1154 2760
478 2452
1841 2764
155 1781
215 1432
1788 2548
193 2665
167 1038
2425 2314
439 1615
269 1187
1222 245
1638 2016
2352 1511
2333 1564
1667 2576
1751...

output:

254 254 254 254 241 254 254 253 254 254 254 254 254 254 254 254 254 254 252 254 254 254 254 227 254 254 254 254 254 254 111 251 254 254 254 14 254 254 254 254 254 254 254 254 157 254 254 254 254 250 254 213 254 254 254 254 254 254 254 254 254 249 254 248 254 254 226 79 184 254 254 254 247 254 254 24...

result:

ok AC

Test #20:

score: 0
Accepted
time: 8ms
memory: 6000kb

input:

7000 7000
4828 3840
4148 2678
1645 2954
5516 1204
4664 285
904 1978
1434 1688
1902 5205
1324 4512
1722 1246
6724 5227
524 196
937 6286
6609 4724
5408 5610
4405 2463
5493 1567
2625 2894
2378 3685
5399 6872
6475 6546
5697 1265
1811 1314
2347 3005
6245 271
2414 434
3492 6948
4447 599
793 6107
464 5353
...

output:

3618 1012 1127 3617 3616 2786 3615 1817 3614 3613 3247 3467 1645 3611 3610 421 700 2902 3609 2139 2312 3608 757 3607 1810 1810 1938 1754 3606 3604 2153 2269 3603 1315 258 3602 3601 1187 3600 3135 3599 1362 3598 3596 2807 3595 3594 771 3593 1647 3592 3591 3590 2892 3589 3588 3140 3587 808 3586 3585 3...

result:

ok AC

Test #21:

score: 0
Accepted
time: 4ms
memory: 5964kb

input:

6993 7000
1576 5558
2853 3183
212 2572
1001 75
3386 6483
401 22
489 6768
6520 1684
6439 6188
3810 6414
4088 1924
371 1666
2822 410
5664 1676
1043 1365
384 2688
4179 6357
6466 4630
2829 4371
116 6817
1535 6172
751 5740
499 2484
2013 4576
6556 670
6177 3847
5344 4280
6103 1055
496 4934
6639 217
6606 4...

output:

882 3660 3658 2395 3657 2494 2897 1717 3656 3655 3654 3653 3652 3651 1375 595 1960 3650 23 1643 3649 1888 2769 2356 1121 1572 3647 2211 3646 3645 3644 3643 3642 3641 3640 3639 2868 3638 2609 3637 1665 492 3636 3635 1644 3634 3631 3630 547 1296 3629 3067 89 3628 3627 3626 541 1962 3014 3625 3624 3620...

result:

ok AC

Test #22:

score: 0
Accepted
time: 4ms
memory: 5996kb

input:

6930 7000
2378 5636
2953 3870
897 2126
112 1756
3302 5114
4591 5593
5408 4899
1204 6313
6254 2214
5360 6680
2354 5865
5959 5969
1628 5317
6396 1006
2402 1767
1921 3373
3758 312
2167 5711
4119 6585
19 3951
1714 1206
3754 4376
4516 307
6312 165
5721 2470
4828 4842
4520 4310
1922 4946
2006 3856
1218 58...

output:

20 3622 3621 3620 3619 2953 3618 131 3617 3616 3615 3614 749 3611 3610 3609 3607 1672 3606 3605 948 318 3604 3046 3602 2778 945 527 3601 3600 3599 3598 509 1762 3596 1714 3595 561 3594 3593 3591 3590 3589 3588 1730 3587 3586 3582 3581 3580 85 796 3579 3578 3577 3576 3575 3574 3573 3572 844 2706 3571...

result:

ok AC

Test #23:

score: 0
Accepted
time: 3ms
memory: 5888kb

input:

6300 7000
1562 45
1716 2699
5291 4828
5063 4588
5888 4130
5901 6109
1476 921
3390 5892
5425 3782
824 5679
2278 6102
6146 5556
4874 2115
2842 2803
1963 5131
3736 2611
320 5272
758 5667
4087 228
5139 760
1812 2968
2897 6117
277 387
336 1322
4319 4597
608 4481
6182 3050
4333 3570
401 1662
3085 3197
537...

output:

3130 3129 1850 1356 3128 1076 3127 3126 1082 3125 835 3124 3119 1309 1686 3118 1436 1594 626 3117 3116 3115 3114 3113 2040 3112 1155 3109 1067 1038 3108 3106 3104 3101 963 1694 3100 3099 1276 2102 3096 2280 3095 3094 3092 1685 3091 3090 3089 103 3088 3087 1504 3085 3062 3084 3083 3082 1340 3081 3080...

result:

ok AC

Test #24:

score: 0
Accepted
time: 3ms
memory: 4992kb

input:

2800 7000
931 1154
1783 1159
2515 1596
1734 1277
825 430
938 208
288 684
970 2075
618 2411
2690 500
223 2162
2093 2765
172 1029
832 1571
89 2333
2301 981
1354 1094
1989 137
2340 1804
2600 1249
1714 2343
1043 2738
1375 1239
804 2578
424 1572
568 1945
2233 297
1890 519
1475 944
2732 1123
2012 927
2232...

output:

399 824 279 822 820 818 455 817 402 816 626 371 681 400 815 268 690 38 814 1 813 549 476 807 48 802 178 749 805 577 804 803 174 802 796 795 794 656 390 793 768 782 822 502 792 117 787 786 785 73 784 783 782 354 781 780 795 420 779 778 250 776 591 786 398 775 772 565 67 75 431 483 641 760 759 242 758...

result:

ok AC

Test #25:

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

input:

52 41
18 31
2 5
22 32
1 50
50 29
9 32
44 27
45 17
26 24
18 30
28 25
38 28
5 47
49 38
23 50
8 3
16 24
29 46
7 52
30 38
33 32
39 32
3 18
50 44
1 35
49 37
18 24
29 6
20 39
40 45
33 28
51 52
26 40
38 43
52 45
39 40
42 34
6 45
32 19
20 52
34 28

output:

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

result:

ok AC

Test #26:

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

input:

291 56
117 283
21 277
128 22
245 45
8 223
150 129
16 15
224 163
288 76
218 238
25 233
100 262
244 101
76 207
286 80
164 238
165 283
133 251
23 235
22 280
65 205
8 30
66 76
232 90
251 287
80 62
58 218
285 225
247 199
149 34
219 16
286 221
174 248
20 58
169 69
229 119
178 216
152 147
148 189
116 207
7...

output:

245 202 244 243 242 241 240 238 237 236 235 234 233 232 56 56 231 230 229 228 168 132 227 226 225 224 223 222 221 238 220 219 218 217 216 215 214 213 212 211 210 209 208 207 39 206 205 204 203 202 201 200 199 198 197 196 195 228 194 193 192 175 191 190 189 188 187 186 98 185 184 182 181 180 179 3 17...

result:

ok AC

Test #27:

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

input:

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

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

result:

ok AC

Test #28:

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

input:

63 1000
22 9
25 11
52 54
34 30
18 8
24 3
42 30
61 51
34 17
36 52
58 9
41 53
19 12
40 3
54 47
23 51
44 59
10 21
35 52
34 56
43 15
39 41
12 37
13 21
55 48
16 57
39 25
26 25
22 57
54 34
63 55
11 27
60 40
41 1
24 59
20 53
14 6
51 35
44 9
47 35
32 39
40 28
9 49
29 27
16 25
56 53
28 56
5 39
35 57
61 37
22...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

result:

ok AC

Test #29:

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

input:

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

output:

1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

result:

ok AC

Test #30:

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

input:

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

output:

1 2 1 1 1 1

result:

ok AC

Test #31:

score: 0
Accepted
time: 3ms
memory: 5980kb

input:

7000 6999
6253 1991
6253 4600
1137 6253
1764 6253
6253 908
6253 2205
6253 213
6253 4399
6300 6253
4601 6253
6253 4884
6937 6253
6253 4070
2646 6253
1007 6253
6552 6253
6253 2115
6253 922
6223 6253
6253 2496
3522 6253
2050 6253
6253 763
6803 6253
6253 3847
2816 6253
6253 6297
6253 471
6253 3211
3203 ...

output:

3517 3516 2451 3258 3515 1798 3514 80 1762 3513 3512 2923 1320 3181 3511 360 3510 3509 2861 3508 3507 142 3161 3506 3505 2231 3504 1069 57 2578 1152 1030 3503 3502 3501 2398 3500 404 347 569 886 3499 2139 3498 869 3497 720 3496 3495 3494 687 2419 3493 3492 3491 131 1344 2177 1149 2003 3490 606 930 3...

result:

ok AC