結果

問題 No.2780 The Bottle Imp
ユーザー AyunaAyuna
提出日時 2024-06-07 22:19:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 5,528 bytes
コンパイル時間 7,017 ms
コンパイル使用メモリ 322,984 KB
実行使用メモリ 35,460 KB
最終ジャッジ日時 2024-06-08 10:32:42
合計ジャッジ時間 7,831 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 32 ms
6,544 KB
testcase_08 AC 31 ms
6,552 KB
testcase_09 AC 31 ms
6,544 KB
testcase_10 AC 33 ms
6,548 KB
testcase_11 AC 34 ms
6,676 KB
testcase_12 AC 49 ms
8,488 KB
testcase_13 AC 49 ms
8,480 KB
testcase_14 AC 31 ms
8,072 KB
testcase_15 AC 31 ms
7,944 KB
testcase_16 AC 27 ms
5,376 KB
testcase_17 AC 27 ms
5,384 KB
testcase_18 AC 31 ms
8,072 KB
testcase_19 AC 30 ms
7,952 KB
testcase_20 AC 30 ms
7,944 KB
testcase_21 AC 26 ms
5,376 KB
testcase_22 AC 15 ms
5,376 KB
testcase_23 AC 22 ms
5,376 KB
testcase_24 AC 26 ms
5,836 KB
testcase_25 AC 39 ms
7,432 KB
testcase_26 AC 26 ms
6,000 KB
testcase_27 AC 28 ms
8,368 KB
testcase_28 AC 28 ms
8,364 KB
testcase_29 AC 32 ms
11,644 KB
testcase_30 AC 20 ms
5,888 KB
testcase_31 AC 47 ms
11,540 KB
testcase_32 AC 21 ms
6,236 KB
testcase_33 AC 66 ms
26,292 KB
testcase_34 AC 80 ms
35,460 KB
testcase_35 AC 17 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 16 ms
5,376 KB
testcase_39 AC 49 ms
14,968 KB
testcase_40 AC 47 ms
14,956 KB
testcase_41 AC 48 ms
14,972 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#if 1

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

using mint93 = modint998244353;
using mint17 = modint1000000007;
using mint = modint;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll, ll>;
template <class T, class S>
using p = pair<T, S>;
#define vec vector
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
template <class T>
using vvv = v<vv<T>>;
using vl = v<ll>;
using vvl = vv<ll>;
using vvvl = vvv<ll>;
using vpl = v<pll>;
constexpr ll TEN(int n) { return (n == 0) ? 1ll : 10ll * TEN(n - 1); }

#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, N) for (ll i = 0; i < (ll)(N); i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)(N); i++)
#define rrep(i, N) for (ll i = N - 1; i >= 0; i--)
#define rrep1(i, N) for (ll i = N; i > 0; i--)
#define fore(i, a) for (auto &i : a)
#define fs first
#define sc second
#define eb emplace_back
#define pb push_back
#define ps push
#define elif else if
#define all(x) (x).begin(), (x).end()
#define UNIQUE(x) (x).erase(unique((x).begin(), (x).end()), (x).end());
#define YES(x) cout << ((x) ? "YES" : "NO") << endl;
#define Yes(x) cout << ((x) ? "Yes" : "No") << endl;
#define yes(x) cout << ((x) ? "yes" : "no") << endl;
#define printans(x) cout << (x == infl ? -1 : x) << endl;
ll sum(vl &x) { return accumulate(all(x), 0ll); }
template <class T>
auto min(const T &a) {
  return *min_element(all(a));
}
template <class T>
auto max(const T &a) {
  return *max_element(all(a));
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
const int inf = (1ll << 29);
const ll infl = (1ll << 60);
const ll mod93 = 998244353ll;
const ll mod17 = 1000000007ll;
int popcnt(uint x) { return __builtin_popcount(x); }
int popcnt(ull x) { return __builtin_popcountll(x); }
int bsr(uint x) { return 32 - __builtin_clz(x); }
int bsr(ull x) { return 64 - __builtin_clzll(x); }
int bsf(uint x) { return __builtin_ctz(x); }
int bsf(ull x) { return __builtin_ctzll(x); }

ostream &operator<<(ostream &os, const mint93 &x) { return os << x.val(); }
ostream &operator<<(ostream &os, const mint17 &x) { return os << x.val(); }
template <class T, class S>
istream &operator>>(istream &is, pair<T, S> &x) {
  return is >> x.fs >> x.sc;
}
template <class T, class S>
ostream &operator<<(ostream &os, pair<T, S> &x) {
  return os << x.fs << " " << x.sc;
}
template <class T>
istream &operator>>(istream &is, v<T> &x) {
  for (auto &y : x) is >> y;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, v<T> &x) {
  for (unsigned int i = 0, size = x.size(); i < size; i++)
    os << x[i] << (i == size - 1 ? "" : " ");
  return os;
}
template <class T>
T popleft(queue<T> &q) {
  T a = q.front();
  q.pop();
  return a;
}
template <class T>
void print(T &t) {
  fore(H, t) cout << H << ' ';
  cout << endl;
}
struct StopWatch {
  bool f = false;
  clock_t st;
  void start() {
    f = true;
    st = clock();
  }
  int msecs() {
    assert(f);
    return (clock() - st) * 1000 / CLOCKS_PER_SEC;
  }
};
ll rand_int(ll l, ll r) {  // [l, r]
  static random_device rd;
  static mt19937 gen(rd());
  return uniform_int_distribution<ll>(l, r)(gen);
}
template <typename T>  // mint93 or mint17
struct Count {
  int N;
  v<T> fact, ifact;
  Count(int N) : N(N) {
    fact.resize(N + 1);
    ifact.resize(N + 1);
    fact[0] = 1;
    rep1(i, N) { fact[i] = fact[i - 1] * i; }
    ifact[N] = T(1) / fact[N];
    rrep1(i, N) { ifact[i - 1] = ifact[i] * i; }
  }
  void extend(int n) {
    int pn = fact.size();
    fact.resize(n + 1);
    ifact.resize(n + 1);
    FOR(i, pn, n + 1) { fact[i] = fact[i - 1] * i; }
    ifact[n] = T(1) / fact[n];
    for (int i = n; i > pn; i--) {
      ifact[i - 1] = ifact[i] * i;
    }
  }
  T nCk(int n, int k) {
    if (k > n || k < 0) return 0;
    if (n >= int(fact.size())) extend(n);
    return fact[n] * ifact[k] * ifact[n - k];
  }
  T nPk(int n, int k) {
    if (k > n || k < 0) return 0;
    if (n >= int(fact.size())) extend(n);
    return fact[n] * ifact[n - k];
  }
  T nHk(int n, int k) {
    if (n == 0 && k == 0) return 1;
    return nCk(n + k - 1, k);
  }
  T catalan(int n) { return nCk(2 * n, n) - nCk(2 * n, n + 1); }
  T catalan(int n, int m, int k) {
    if (n > m + k || k < 0)
      return 0;
    else
      return nCk(n + m, n) - nCk(n + m, m + k + 1);
  }
};
#endif

// #define _GLIBCXX_DEBUG


int main() {
  int n;
  cin >> n;
  vvl graph(n);
  v<bool> visited(n);
  scc_graph g(n);
  rep(i, n){
    int m;
    cin >> m;
    graph[i].resize(m);
    cin >> graph[i];
    fore(j, graph[i]) {
      j--;
      visited[j] = true;
      g.add_edge(i, j);
    }
  }
  rep1(i, n - 1) {
    if (!visited[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  auto ll = g.scc();
  vl inv(n);
  for (int i = 0; i < ll.size(); i++){
    fore(j, ll[i]) inv[j] = i; 
  }
  vvl ng(ll.size());
  for (int i = 0; i < n; i++){
    fore(j, graph[i]){
      ng[inv[i]].pb(inv[j]);
    }
  }
  fore(lis, ng) {
    sort(all(lis));
    UNIQUE(lis);
  }
  v<bool> nvisited(ll.size());
  nvisited[inv[0]] = true;
  for (int i = 0; i < ll.size(); i++){
    if (!nvisited[i]){
      cout << "No" << endl;
      return 0;
    }
    fore(j, ng[i]){
      if (j == i + 1)
        nvisited[i + 1] = true;
    }
  }
  cout << "Yes" << endl;
}
0