結果
| 問題 |
No.2780 The Bottle Imp
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-07 22:39:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,012 bytes |
| コンパイル時間 | 2,689 ms |
| コンパイル使用メモリ | 218,436 KB |
| 最終ジャッジ日時 | 2025-02-21 20:28:05 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 WA * 4 |
ソースコード
#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>());
rep(u, n) {
ll m;
cin >> m;
rep(mi, m) {
ll v;
cin >> v, v--;
g[u].push_back(v);
}
}
atcoder::scc_graph sg(n);
for (ll v = 1; v < n; v++)
sg.add_edge(0, v);
for (ll u = 1; u < n; u++)
for (const auto v : g[u])
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;
}