QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#683926#9525. Welcome to Join the Online Meeting!maspyAC ✓106ms65376kbC++2320.5kb2024-10-28 03:06:272024-10-28 03:06:29

Judging History

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

  • [2024-10-28 03:06:29]
  • 评测
  • 测评结果:AC
  • 用时:106ms
  • 内存:65376kb
  • [2024-10-28 03:06:27]
  • 提交

answer

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

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

  auto dfs = [&](auto& dfs, int v) -> void {
    low[v] = ord[v] = now++;
    path.eb(v);
    for (auto&& [frm, to, cost, id]: G[v]) {
      if (ord[to] == -1) {
        dfs(dfs, to), chmin(low[v], low[to]);
      } else {
        chmin(low[v], ord[to]);
      }
    }
    if (low[v] == ord[v]) {
      while (1) {
        int u = POP(path);
        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 5 "main.cpp"

void solve() {
  LL(N, M, K);
  vc<int> close(N);
  FOR(k, K) {
    INT(v);
    --v;
    close[v] = 1;
  }

  Graph<int, 1> G(N);
  FOR(M) {
    INT(a, b);
    --a, --b;
    FOR(2) {
      swap(a, b);
      if (!close[a]) G.add(a, b);
    }
  }
  G.build();

  auto [nc, comp] = strongly_connected_component(G);
  int v = -1;
  FOR(i, N) if (comp[i] == 0) v = i;
  vc<int> vis(N);
  vvc<int> ANS;

  auto dfs = [&](auto& dfs, int v) -> void {
    vc<int> S;
    for (auto& e: G[v]) {
      if (!vis[e.to]) S.eb(e.to);
      vis[e.to] = 1;
    }
    if (S.empty()) return;
    vc<int> out;
    out.eb(1 + v);
    out.eb(len(S));
    for (auto& x: S) out.eb(1 + x);

    ANS.eb(out);
    for (auto& w: S) dfs(dfs, w);
  };
  vis[v] = 1;
  dfs(dfs, v);

  FOR(w, N) if (!vis[w]) return No();

  Yes();
  print(len(ANS));
  for (auto& out: ANS) print(out);
}

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

Yes
1
2 3 1 3 4

result:

ok ok

Test #2:

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

input:

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

output:

No

result:

ok ok

Test #3:

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

input:

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

output:

Yes
1
2 3 3 4 1

result:

ok ok

Test #4:

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

input:

6 6 0

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

output:

No

result:

ok ok

Test #5:

score: 0
Accepted
time: 106ms
memory: 65376kb

input:

200000 199999 2
142330 49798
49798 116486
116486 64386
64386 192793
192793 61212
61212 138489
138489 83788
83788 89573
89573 8596
8596 156548
156548 41800
41800 14478
14478 27908
27908 82806
82806 9353
9353 160166
160166 92308
92308 36265
36265 126943
126943 190578
190578 191148
191148 177381
177381...

output:

Yes
199998
200000 2 70619 64617
70619 1 61733
61733 1 186765
186765 1 130197
130197 1 60967
60967 1 185321
185321 1 175404
175404 1 36785
36785 1 46281
46281 1 117056
117056 1 196740
196740 1 106390
106390 1 80009
80009 1 93912
93912 1 182518
182518 1 156904
156904 1 108072
108072 1 11885
11885 1 29...

result:

ok ok

Test #6:

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

input:

199999 199998 1
136702
159826 166341
166341 59559
59559 169672
169672 102084
102084 136269
136269 57057
57057 59116
59116 119963
119963 85663
85663 33942
33942 84604
84604 189395
189395 154906
154906 22175
22175 144902
144902 198523
198523 35993
35993 35690
35690 47504
47504 104458
104458 68253
6825...

output:

Yes
199997
199999 2 164642 146100
164642 1 189122
189122 1 68022
68022 1 112813
112813 1 29929
29929 1 81207
81207 1 182732
182732 1 94588
94588 1 198013
198013 1 180555
180555 1 123535
123535 1 144321
144321 1 164463
164463 1 53519
53519 1 129611
129611 1 85679
85679 1 1403
1403 1 178125
178125 1 9...

result:

ok ok

Test #7:

score: 0
Accepted
time: 103ms
memory: 59804kb

input:

199998 199997 0

67665 130538
130538 101337
101337 73749
73749 138128
138128 1274
1274 108069
108069 50961
50961 7039
7039 109946
109946 170551
170551 193330
193330 113590
113590 92775
92775 2146
2146 43591
43591 125033
125033 75583
75583 173991
173991 46820
46820 3986
3986 163272
163272 91657
91657...

output:

Yes
199996
199998 2 193401 179438
193401 1 135386
135386 1 20788
20788 1 149607
149607 1 52583
52583 1 35364
35364 1 1465
1465 1 175228
175228 1 49013
49013 1 104480
104480 1 78367
78367 1 48226
48226 1 53593
53593 1 164579
164579 1 146147
146147 1 180648
180648 1 77787
77787 1 92530
92530 1 168043
...

result:

ok ok

Test #8:

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

input:

199997 199996 1
158877
35837 79489
79489 72932
72932 14238
14238 73007
73007 66909
66909 49015
49015 129581
129581 138449
138449 94774
94774 189625
189625 23578
23578 31043
31043 146625
146625 161587
161587 136966
136966 184859
184859 27587
27587 155616
155616 72392
72392 195320
195320 75551
75551 1...

output:

No

result:

ok ok

Test #9:

score: 0
Accepted
time: 12ms
memory: 14424kb

input:

200000 199999 1
29111
29111 80079
29111 131587
29111 197066
29111 125194
29111 156736
50697 29111
29111 74382
113595 29111
29111 26046
29111 172868
178564 29111
174875 29111
93471 29111
88216 29111
29111 147893
29111 145746
29111 34038
146500 29111
67862 29111
29111 19222
29111 121535
29111 49102
29...

output:

No

result:

ok ok

Test #10:

score: 0
Accepted
time: 15ms
memory: 23636kb

input:

199999 199998 2
52512 104330
130511 66864
139434 66864
92884 66864
66864 185580
184115 66864
137395 66864
66864 43463
118395 66864
111697 66864
66864 133237
66864 112507
66864 140264
66864 10
66864 151082
155779 66864
107988 66864
148839 66864
66864 40909
172685 66864
66864 189374
180054 66864
49 66...

output:

Yes
2
199999 1 66864
66864 199997 130511 139434 92884 185580 184115 137395 43463 118395 111697 133237 112507 140264 10 151082 155779 107988 148839 40909 172685 189374 180054 49 41830 19259 186287 41932 21357 66485 95229 126195 72801 154651 48615 111519 156500 156919 60203 11260 164641 168543 130264 ...

result:

ok ok

Test #11:

score: 0
Accepted
time: 22ms
memory: 23340kb

input:

199998 199997 0

77056 67665
130538 77056
77056 101337
73749 77056
77056 138128
1274 77056
77056 108069
50961 77056
77056 7039
77056 109946
77056 170551
193330 77056
113590 77056
77056 92775
2146 77056
43591 77056
77056 125033
75583 77056
173991 77056
46820 77056
77056 3986
77056 163272
91657 77056
...

output:

Yes
2
199998 1 77056
77056 199996 67665 130538 101337 73749 138128 1274 108069 50961 7039 109946 170551 193330 113590 92775 2146 43591 125033 75583 173991 46820 3986 163272 91657 92212 191670 170218 149297 164182 6856 61891 95065 7257 47282 126716 84031 52189 32847 63118 134126 143246 30142 58215 33...

result:

ok ok

Test #12:

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

input:

1000 499500 999
458 720 932 821 847 788 447 593 430 896 257 238 380 924 968 30 389 306 278 824 83 342 329 513 476 313 714 348 602 105 758 777 663 1000 20 756 546 256 123 340 69 244 772 625 390 557 911 272 496 127 409 436 845 574 958 921 24 17 770 630 851 147 178 976 77 181 230 723 974 345 501 683 24...

output:

Yes
1
987 999 516 5 990 603 581 613 664 339 669 702 571 159 399 397 347 481 43 709 916 191 33 517 178 751 897 868 687 155 993 78 378 865 108 677 382 158 937 496 4 541 398 367 237 825 364 518 679 578 199 566 180 894 275 273 305 805 933 524 30 576 707 437 38 513 762 56 349 785 186 461 15 44 991 366 42...

result:

ok ok

Test #13:

score: 0
Accepted
time: 18ms
memory: 10936kb

input:

1000 499000 765
622 257 281 601 593 967 704 173 609 700 782 592 356 595 431 307 933 886 213 478 8 832 877 606 335 253 420 631 345 179 961 437 238 641 513 997 192 483 152 951 580 331 401 122 155 814 228 633 372 918 346 464 3 992 416 953 650 668 971 899 76 575 880 85 194 541 26 348 93 815 554 64 850 5...

output:

Yes
1
998 999 884 349 768 79 712 469 420 852 946 574 302 287 393 114 145 745 929 118 282 977 666 856 661 523 275 99 256 518 78 416 473 283 463 786 858 188 686 647 936 851 810 885 866 35 357 711 555 243 696 97 122 246 927 38 679 595 690 314 755 477 156 324 724 984 931 486 119 903 58 212 146 698 254 6...

result:

ok ok

Test #14:

score: 0
Accepted
time: 11ms
memory: 21968kb

input:

999 300000 98
544 367 966 146 474 309 291 482 953 116 340 59 765 566 227 176 371 672 170 739 120 931 23 858 153 884 258 842 763 405 104 957 596 978 732 515 497 269 174 551 653 690 755 808 288 574 17 356 500 665 827 172 987 240 154 824 220 430 722 950 534 400 413 908 671 12 427 818 187 335 572 644 52...

output:

Yes
8
999 609 401 109 964 435 252 933 68 967 322 153 251 826 881 389 779 903 667 491 69 613 458 475 873 767 917 137 328 509 821 378 330 255 882 660 612 489 133 171 471 972 589 357 232 682 827 169 626 211 270 358 253 541 333 468 474 122 477 71 15 402 116 516 44 630 641 957 152 483 9 871 370 449 768 2...

result:

ok ok

Test #15:

score: 0
Accepted
time: 13ms
memory: 4000kb

input:

10000 500000 10000
1905 4872 6021 8458 3220 7251 6356 3194 996 2320 298 7850 3567 2244 4361 7462 8058 9852 3057 6409 2288 9712 8533 5380 7131 970 2261 134 1179 1665 7329 442 8996 8203 7168 5946 7893 8282 9474 2445 1762 4900 101 6631 4588 7670 7716 7010 6113 5654 5308 3451 130 3205 2959 4898 374 6178...

output:

No

result:

ok ok

Test #16:

score: 0
Accepted
time: 13ms
memory: 3924kb

input:

10000 500000 9998
5272 7519 3021 7043 2522 2940 9960 3860 7595 3760 8035 2085 572 234 8292 3636 9619 6749 884 6669 8536 570 9353 2803 160 6085 5838 2812 7764 8722 2431 8854 2183 2032 7731 5404 5516 1574 4864 1431 8527 5506 1012 5713 8665 26 976 6010 4888 5975 6993 3187 7227 8438 6812 5903 1738 6467 ...

output:

No

result:

ok ok

Test #17:

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

input:

10000 500000 1234
7096 8517 9305 874 7758 730 2653 6237 2494 4290 2280 892 9081 2308 6418 3258 1690 103 9850 6778 9724 1914 1561 1361 3776 160 1892 1394 7981 3050 6013 5452 8769 7341 3259 6011 8672 4500 1930 8758 5103 4509 2782 1354 1583 8663 1088 2156 3254 7150 3824 4768 8230 7533 3277 8910 8135 19...

output:

Yes
534
10000 98 4498 2853 9761 5520 8374 8552 8871 5814 5980 3372 5068 8326 9345 4277 7068 6078 4741 1919 6943 8324 8615 2984 2057 7559 8378 9024 1587 461 6280 6518 9774 2294 3206 2278 5082 5541 1373 9242 7878 4280 3587 3708 4729 5063 1714 5899 2898 9266 5430 6229 7485 8274 9579 4333 8125 6734 5810...

result:

ok ok

Test #18:

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

input:

10000 500000 0

6605 3715
1237 3040
3617 2124
4550 1766
8159 4808
7027 9779
7053 1803
3973 6790
8233 2873
7636 6894
6821 9714
8280 8440
261 6160
1279 3627
5816 9131
8167 1332
6763 3029
9605 4045
921 9926
6547 4760
3618 7832
5961 6497
1255 5646
5567 621
5732 2860
88 3501
3866 6046
7188 6203
3337 2873...

output:

Yes
518
10000 100 1654 7854 635 9675 8257 789 6005 6284 4750 918 5733 674 6437 975 3285 7156 7272 6998 9801 4079 4202 1620 8303 8530 1103 1871 4784 2915 375 5761 5249 8254 916 5475 4111 5448 5150 5890 7359 9519 9817 4197 1416 981 7598 3272 6568 234 2281 9717 3873 4407 6095 5030 2965 2396 4242 9207 2...

result:

ok ok

Test #19:

score: 0
Accepted
time: 34ms
memory: 36144kb

input:

20000 499999 321
13495 16729 10971 3389 7920 17768 11943 12054 6426 13331 6453 15959 6842 12610 18437 12930 4597 7386 8506 52 17373 2492 18849 19694 8432 12552 8663 4836 5370 3125 4323 15529 5916 14378 13756 15147 19826 7961 3188 4919 14256 5230 16288 13867 6039 13451 12861 9057 12645 19486 16719 19...

output:

Yes
1778
20000 50 9523 3364 14 629 13342 726 5306 10620 17319 1864 7921 16989 17710 17111 10040 15213 11915 16813 6516 18408 17189 12092 14422 12798 12410 640 9266 5711 2528 6572 2909 15193 4071 19275 4895 3207 18657 9667 11117 12103 10264 5278 13546 3963 18283 7860 7182 15640 10339 17833
9523 44 13...

result:

ok ok

Test #20:

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

input:

20000 499998 456
17380 3548 17148 12088 15694 2886 15042 15060 4903 3288 13810 5360 7487 15472 1934 6496 19753 7795 9485 16913 17980 18738 18003 3795 5186 18128 15284 3276 16833 13161 6707 8941 947 5088 4974 13222 1790 14903 14837 4315 17583 12119 15871 6961 11561 3674 18427 2207 1556 19736 719 2326...

output:

Yes
1829
20000 54 3756 7409 16067 10847 13010 13426 289 10733 13456 5572 3376 1659 10351 19540 15022 16052 4542 1386 16004 8405 4912 13142 18955 10712 894 320 16166 12289 12158 339 15534 535 18464 19149 10083 12954 8325 4890 9743 11572 6099 16477 17861 6424 1697 18025 1138 7277 14656 9565 11856 1695...

result:

ok ok

Test #21:

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

input:

100000 500000 1235
3510 14575 57589 88714 29299 62839 6733 25039 17686 8112 24858 274 16916 83976 25181 57773 49758 65223 33663 47471 12200 8551 57927 21092 67375 77093 76589 91355 94075 17071 50791 43800 72672 54280 19504 106 10971 87577 40091 88380 81937 27327 24188 78489 92382 43581 8875 22402 41...

output:

No

result:

ok ok

Test #22:

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

input:

100000 500000 9
34008 13155 90342 28233 23089 86546 14071 6854 11360
3498 65486
65603 70184
14269 18649
79366 11163
66926 49216
4445 76420
50121 20493
2808 43301
18218 44910
92999 97448
13760 37138
15100 36649
34074 1879
72027 68411
54611 87760
1896 60316
43650 8286
34285 74403
21309 96104
49344 941...

output:

Yes
28613
100000 12 931 62525 69431 87929 67861 67265 16244 54815 62510 96873 94392 62789
931 6 53903 21654 86403 21332 58777 40297
53903 7 99875 7976 92385 1560 58689 65666 7161
99875 6 43291 96416 44538 53203 93069 86501
43291 11 82157 61725 20484 47802 47113 31260 41443 14396 13488 994 23026
8215...

result:

ok ok

Test #23:

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

input:

100000 500000 1
75076
9583 32552
72566 77581
74823 25463
58197 78380
62002 94563
99622 60434
39479 68180
1722 38894
43269 85989
33777 78513
5464 79304
57968 37134
88958 60066
61043 23394
50002 93317
59516 46962
55978 3705
2504 341
70466 21789
42193 45686
1370 18780
91444 2274
93546 66571
97443 53551...

output:

Yes
28456
100000 13 76450 94576 61263 43935 44692 38731 50154 93374 77315 12332 99723 84808 76832
76450 14 47675 50108 99511 4766 92297 28933 5502 25220 63831 19716 44114 58670 51687 62963
47675 7 79523 63246 14340 57167 78430 27418 66209
79523 11 37813 90352 65050 56682 86922 49675 61789 26302 7436...

result:

ok ok

Test #24:

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

input:

100000 500000 0

39862 49976
22596 40406
37185 98022
80733 93561
81387 94842
25064 61254
42694 16911
22623 87861
89266 37654
59510 12230
43457 79569
73883 19406
63275 92754
22177 11799
5763 44974
1570 83476
79123 73330
45165 77314
63415 32676
70388 8398
22032 77785
63620 61574
23429 41486
30923 1236...

output:

Yes
28658
100000 13 69530 80512 57140 53706 95809 10070 75754 80128 44246 64969 55397 74091 41568
69530 11 14561 60825 24678 93228 37969 46095 16157 76416 16276 6545 6346
14561 11 4385 39805 75476 85590 63302 54884 47368 62603 22904 64368 31616
4385 14 27589 40371 92380 86390 66451 4308 12175 40904 ...

result:

ok ok

Test #25:

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

input:

199999 200000 10
162044 184301 102211 174303 129412 46215 153004 13679 113247 194319
100393 176945
52810 193834
159859 44467
119931 61763
196292 30856
21297 175055
20174 1882
11250 184866
74000 1054
74272 134956
41299 186242
162575 63218
119189 12678
29884 5001
148164 16567
24612 169902
77735 135002...

output:

No

result:

ok ok

Test #26:

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

input:

200000 199999 0

142790 145621
180161 104270
112230 88214
154000 63048
188285 141046
185739 50230
142683 197737
141276 49672
41219 95859
175530 171250
171226 174408
151297 88982
28928 71368
199034 63185
116370 106685
192890 167797
132366 79091
78160 89965
177169 151554
172583 127365
9032 60583
78786...

output:

No

result:

ok ok

Test #27:

score: 0
Accepted
time: 80ms
memory: 49520kb

input:

200000 500000 245
193722 185527 109052 75916 93935 24076 79627 20964 180786 120016 132778 186582 144529 16308 58727 114586 130490 34200 113593 7386 151039 39324 175706 195617 169880 139107 160903 183556 167931 124336 92216 181943 41472 98648 191217 191760 19769 86540 4125 65866 133876 106754 96372 1...

output:

No

result:

ok ok

Test #28:

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

input:

200000 500000 14
142703 65403 129451 151977 165363 20230 132897 87039 9024 158327 31353 194121 16577 146056
139648 187616
8050 35431
127655 35285
195736 80740
3874 174224
168938 136840
97592 176911
12210 58008
85816 66096
61709 179153
69540 1567
86595 14951
182066 29930
183615 37773
166329 61767
167...

output:

No

result:

ok ok

Test #29:

score: 0
Accepted
time: 106ms
memory: 57508kb

input:

200000 500000 1
5880
85775 146428
142622 151159
88421 138441
169300 66421
147351 32187
62008 74476
82579 109015
176101 15964
50525 172923
142682 150232
178015 197099
29910 154380
124900 65984
825 137825
194984 139256
31396 65802
141485 14608
126721 85235
193397 167129
98424 54611
63857 8244
68507 68...

output:

Yes
86689
200000 5 187862 176866 163297 46653 172247
187862 5 110733 32684 19881 3692 72967
110733 8 114486 132702 163385 146157 169379 13846 66597 147600
114486 3 61067 99246 193983
61067 2 34146 81701
34146 3 100033 49291 5384
100033 7 191929 125042 55502 101288 194868 162203 149628
191929 5 11294...

result:

ok ok

Test #30:

score: 0
Accepted
time: 46ms
memory: 24212kb

input:

199999 199998 73589
144387 49530 75323 115971 116495 141238 92902 186288 75011 21274 196 62128 161581 112516 16226 166382 73692 120539 170346 127146 153896 57832 23870 56030 110186 132465 101619 681 13908 5901 194116 151154 160650 78720 87497 131676 94642 65227 153151 67720 61825 132140 114363 76085...

output:

Yes
126410
199998 2 199999 199997
199997 1 199995
199995 2 199993 199996
199993 2 199992 199994
199992 1 199991
199991 1 199988
199988 2 199986 199990
199986 1 199980
199980 2 199973 199985
199973 3 199981 199979 199964
199964 3 199959 199974 199972
199959 3 199954 199963 199962
199954 4 199958 1999...

result:

ok ok

Test #31:

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

input:

2 1 1
1
1 2

output:

Yes
1
2 1 1

result:

ok ok

Test #32:

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

input:

2 1 0

1 2

output:

Yes
1
2 1 1

result:

ok ok

Extra Test:

score: 0
Extra Test Passed