結果

問題 No.2780 The Bottle Imp
ユーザー にしろにしろ
提出日時 2024-08-15 16:01:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 3,263 bytes
コンパイル時間 5,093 ms
コンパイル使用メモリ 313,300 KB
実行使用メモリ 29,944 KB
最終ジャッジ日時 2024-08-15 16:01:24
合計ジャッジ時間 9,308 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 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 41 ms
9,232 KB
testcase_08 AC 41 ms
9,364 KB
testcase_09 AC 39 ms
9,232 KB
testcase_10 AC 44 ms
9,368 KB
testcase_11 AC 40 ms
9,364 KB
testcase_12 AC 63 ms
14,604 KB
testcase_13 AC 64 ms
14,724 KB
testcase_14 AC 34 ms
6,912 KB
testcase_15 AC 36 ms
6,916 KB
testcase_16 AC 32 ms
6,912 KB
testcase_17 AC 32 ms
6,656 KB
testcase_18 AC 32 ms
6,940 KB
testcase_19 AC 33 ms
6,912 KB
testcase_20 AC 33 ms
6,912 KB
testcase_21 AC 31 ms
6,912 KB
testcase_22 AC 17 ms
5,800 KB
testcase_23 AC 27 ms
6,940 KB
testcase_24 AC 32 ms
8,376 KB
testcase_25 AC 51 ms
11,616 KB
testcase_26 AC 33 ms
8,052 KB
testcase_27 AC 27 ms
7,612 KB
testcase_28 AC 28 ms
7,484 KB
testcase_29 AC 31 ms
10,236 KB
testcase_30 AC 25 ms
8,312 KB
testcase_31 AC 48 ms
11,400 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 65 ms
26,232 KB
testcase_34 AC 71 ms
29,944 KB
testcase_35 AC 16 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 17 ms
5,376 KB
testcase_39 AC 49 ms
14,432 KB
testcase_40 AC 48 ms
14,556 KB
testcase_41 AC 48 ms
14,412 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ul = unsigned long;
using ld = long double;
using st = string;
using mint = atcoder::modint998244353;
using Mint = atcoder::modint1000000007;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define vvvvl vector<vector<vector<vector<ll>>>>
#define vd vector<ld>
#define vvd vector<vector<ld>>
#define vvvd vector<vector<vector<ld>>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vvvb vector<vector<vector<bool>>>
#define vs vector<string>
#define vvs vector<vector<string>>
#define vvvs vector<vector<vector<string>>>
#define vp vector<pair<ll,ll>>
#define vvp vector<vector<pair<ll,ll>>>
#define vvvp vector<vector<vector<pair<ll,ll>>>>
#define vm vector<mint>
#define vvm vector<vector<mint>>
#define vM vector<Mint>
#define vvM vector<vector<Mint>>
#define cmx(n,v) n=n<v?v:n
#define cmn(n,v) n=n>v?v:n
#define all(n) begin(n),end(n)
#define nxp(a) next_permutation(all(a))
#define rev(n) reverse(all(n))
#define sor(n) stable_sort(all(n))
#define rep(i,n) for(ll i=0;i<(n);++i)
#define reprev(i,n) for(ll i=n-1;0<=i;--i)
#define rrep(i,a,n) for(ll i=a;i<(n);++i)
#define sz(n) n.size()
#define bit(j,i) (i&(1<<j))
#define yn(x) cout << (x?"Yes":"No") << endl;
#define lb(vec,src) lower_bound(vec.begin(),vec.end(),src)-vec.begin()
#define ub(vec,src) upper_bound(vec.begin(),vec.end(),src)-vec.begin()
#define lb2(vec,src) *lower_bound(vec.begin(),vec.end(),src)
#define ub2(vec,src) *upper_bound(vec.begin(),vec.end(),src)
#define mne1(a) min_element(all(a))
#define mxe1(a) max_element(all(a))
#define mne2(a) *min_element(all(a))
#define mxe2(a) *max_element(all(a))
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());}
const ll inf = 9e18;

int main() {
    int n;
    cin >> n;
    scc_graph g(n);//AtCoder Libraryのsccを使用
    vector b(n,vector<int>(0));//チェック2にて使用する入力をそのまま管理する配列/vector2<int>はvector<vector<int>>を表します(34行目にて定義)
    rep(j,n){
        int m;
        cin >> m;
        rep(i,m){
            int a;
            cin >> a;
            a--;
            b[j].push_back(a);
            g.add_edge(j,a);
        }
    }
    vector<vector<int>> sorted = g.scc();//強連結成分分解からのトポロジカルソート(AtCoder Libraryの機能)
    vector<int> topol(n);//その頂点(人)が何番目の強連結成分に存在するかを保存
    rep(j,sorted.size()){
        for(int i : sorted[j]){
            topol[i] = j;
        }
    }
    bool  ans = 0;//二つのチェックを通ったらYes
    ans=(topol[0]==0);

    rep(j,sorted.size()-1){//チェック2:トポロジカルソートされた強連結成分たちについてある強連結成分から次の強連結成分へ移動可能か
        bool c = 0;
        for(int i : sorted[j]){
            for(int k : b[i]){
                if(topol[k] == j+1) c = 1;
            }
        }
        if(c) continue;
        ans = 0;//次の強連結成分へ移動できないなら答えはNo
        break;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0