結果

問題 No.2780 The Bottle Imp
ユーザー maeshunmaeshun
提出日時 2024-06-08 13:07:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,799 bytes
コンパイル時間 4,363 ms
コンパイル使用メモリ 281,248 KB
実行使用メモリ 36,424 KB
最終ジャッジ日時 2024-06-08 13:07:32
合計ジャッジ時間 7,124 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 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 1 ms
5,376 KB
testcase_07 AC 35 ms
8,600 KB
testcase_08 AC 35 ms
8,484 KB
testcase_09 AC 36 ms
8,600 KB
testcase_10 AC 36 ms
8,480 KB
testcase_11 AC 36 ms
8,480 KB
testcase_12 AC 68 ms
13,088 KB
testcase_13 AC 67 ms
13,076 KB
testcase_14 AC 37 ms
7,248 KB
testcase_15 AC 37 ms
7,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 34 ms
7,324 KB
testcase_19 AC 35 ms
7,376 KB
testcase_20 AC 35 ms
7,244 KB
testcase_21 WA -
testcase_22 AC 16 ms
5,376 KB
testcase_23 AC 25 ms
5,540 KB
testcase_24 AC 29 ms
7,684 KB
testcase_25 AC 45 ms
10,388 KB
testcase_26 AC 29 ms
6,944 KB
testcase_27 AC 30 ms
8,060 KB
testcase_28 AC 30 ms
8,056 KB
testcase_29 WA -
testcase_30 AC 37 ms
10,196 KB
testcase_31 AC 53 ms
12,876 KB
testcase_32 AC 22 ms
5,520 KB
testcase_33 AC 69 ms
28,696 KB
testcase_34 AC 125 ms
36,424 KB
testcase_35 AC 18 ms
5,376 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 18 ms
5,376 KB
testcase_39 AC 62 ms
15,420 KB
testcase_40 AC 52 ms
15,552 KB
testcase_41 WA -
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);
    dsu r(n);
    rep(i,n) {
        int m;
        cin >> m;
        rep(j,m) {
            int b;
            cin >> b;
            --b;
            g.add_edge(i, b);
            r.merge(i,b);
            f[i].push_back(b);
        }
    }
    if(r.groups().size()!=1){
        cout<<"No"<<endl;
        return 0;
    }
    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>> rev(m);
    rep(i,n) {
        for(int v : f[i]) {
            rev[l[uf.leader(v)]].push_back(l[uf.leader(i)]);
        }   
    }
    dbg(rev, d);
    rep(i,m) {
        sort(rev[i].begin(),rev[i].end());
        rev[i].erase(unique(rev[i].begin(),rev[i].end()), rev[i].end());
        d[i] = rev[i].size();
    }
    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();
        for(int v : rev[u]) {
            d[v]--;
            if(d[v]==0) q.push(v);
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}
0