結果
問題 | No.2780 The Bottle Imp |
ユーザー |
|
提出日時 | 2024-06-07 22:45:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 901 bytes |
コンパイル時間 | 2,491 ms |
コンパイル使用メモリ | 218,104 KB |
最終ジャッジ日時 | 2025-02-21 20:29:47 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <atcoder/scc> #include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll n; cin >> n; vector g(n, vector<ll>()); atcoder::scc_graph sg(n); rep(u, n) { ll m; cin >> m; rep(mi, m) { ll v; cin >> v, v--; g[u].push_back(v); sg.add_edge(u, v); } } auto res = sg.scc(); bool ok = true; set<ll> st = {0}; for (const auto &now : res) { bool found = false; set<ll> nex; for (const auto u : now) { found |= st.count(u); for (const auto v : g[u]) nex.insert(v); } ok &= found; if (!ok) break; swap(st, nex); } cout << (ok ? "Yes" : "No") << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }