結果
| 問題 | 
                            No.2780 The Bottle Imp
                             | 
                    
| コンテスト | |
| ユーザー | 
                             eve__fuyuki
                         | 
                    
| 提出日時 | 2024-06-08 13:29:30 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 55 ms / 2,000 ms | 
| コード長 | 1,273 bytes | 
| コンパイル時間 | 2,377 ms | 
| コンパイル使用メモリ | 210,204 KB | 
| 最終ジャッジ日時 | 2025-02-21 20:56:41 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 40 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/scc>
using namespace std;
using namespace atcoder;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}
int main() {
    fast_io();
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    scc_graph scc(n);
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        for (int j = 0; j < m; j++) {
            int a;
            cin >> a;
            a--;
            g[i].push_back(a);
            scc.add_edge(i, a);
        }
    }
    auto sccs = scc.scc();
    vector<int> scc_index(n);
    for (int i = 0; i < sccs.size(); i++) {
        for (auto v : sccs[i]) {
            scc_index[v] = i;
        }
    }
    if (scc_index[0] != 0) {
        cout << "No" << endl;
        return 0;
    }
    int l = sccs.size();
    vector<bool> ok(l - 1);
    for (int u = 0; u < n; u++) {
        for (int v : g[u]) {
            if (scc_index[u] == scc_index[v]) {
                continue;
            }
            if (scc_index[v] == scc_index[u] + 1) {
                ok[scc_index[u]] = true;
            }
        }
    }
    for (int i = 0; i < l - 1; i++) {
        if (!ok[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
            
            
            
        
            
eve__fuyuki