結果

問題 No.2780 The Bottle Imp
ユーザー maeshunmaeshun
提出日時 2024-06-08 13:20:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,836 bytes
コンパイル時間 4,934 ms
コンパイル使用メモリ 279,604 KB
実行使用メモリ 36,172 KB
最終ジャッジ日時 2024-06-08 13:21:02
合計ジャッジ時間 8,436 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 71 ms
10,712 KB
testcase_08 AC 69 ms
10,716 KB
testcase_09 AC 71 ms
10,840 KB
testcase_10 AC 70 ms
10,840 KB
testcase_11 AC 69 ms
10,840 KB
testcase_12 AC 148 ms
19,044 KB
testcase_13 AC 149 ms
18,888 KB
testcase_14 AC 34 ms
7,080 KB
testcase_15 AC 35 ms
6,956 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 34 ms
6,956 KB
testcase_19 AC 35 ms
7,080 KB
testcase_20 AC 35 ms
6,952 KB
testcase_21 WA -
testcase_22 AC 25 ms
5,992 KB
testcase_23 AC 30 ms
6,888 KB
testcase_24 AC 58 ms
9,436 KB
testcase_25 AC 106 ms
14,076 KB
testcase_26 AC 41 ms
8,424 KB
testcase_27 AC 31 ms
7,768 KB
testcase_28 AC 30 ms
7,644 KB
testcase_29 AC 45 ms
11,548 KB
testcase_30 AC 46 ms
10,352 KB
testcase_31 AC 54 ms
11,752 KB
testcase_32 AC 23 ms
5,376 KB
testcase_33 AC 74 ms
28,164 KB
testcase_34 AC 133 ms
36,172 KB
testcase_35 AC 18 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 19 ms
5,376 KB
testcase_39 AC 56 ms
15,216 KB
testcase_40 AC 55 ms
15,336 KB
testcase_41 AC 55 ms
15,336 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

int main()
{
    int n;
    cin >> n;
    scc_graph g(n);
    vector<vector<int>> f(n);
    dsu uf(n);
    rep(i,n) {
        int m;
        cin >> m;
        rep(j,m) {
            int b;
            cin >> b;
            --b;
            g.add_edge(i, b);
            f[i].push_back(b);
        }
    }
    int m = 0;
    map<int, int> l;
    for(auto  G : g.scc()) {
        for(int v : G) {
            uf.merge(v, G[0]);
        }
        l[uf.leader(G[0])] = m;
        m++;
    }
    vector<int> d(m);
    vector<vector<int>> G(m);
    rep(i,n) {
        for(int v : f[i]) {
            if(uf.leader(v)==uf.leader(i)) continue;
            G[l[uf.leader(i)]].push_back(l[uf.leader(v)]);
        }   
    }
    rep(i,m) {
        sort(G[i].begin(),G[i].end());
        G[i].erase(unique(G[i].begin(),G[i].end()), G[i].end());
    }
    dbg(G);
    rep(i,m) {
        for(int v : G[i]) {
            d[v]++;
        }
    }
    queue<int> q;
    rep(i,m) {
        if(d[i]==0) q.push(i);
    }
    while(!q.empty()) {
        if(q.size()>=2){
            cout<<"No"<< endl;
            return 0;
        }
        int u = q.front();q.pop();
        m--;
        for(int v : G[u]) {
            d[v]--;
            if(d[v]==0) q.push(v);
        }
    }
    if(m==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}
0