結果

問題 No.2780 The Bottle Imp
ユーザー otoshigo
提出日時 2024-06-07 21:58:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,361 bytes
コンパイル時間 2,135 ms
コンパイル使用メモリ 203,760 KB
最終ジャッジ日時 2025-02-21 20:17:09
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,s,t) for(ll i=s;i<(ll)(t);i++)
#define rrep(i,s,t) for(ll i=(ll)(t)-1;i>=(ll)s;i--)
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)

#define TT template<typename T>
TT using vec=vector<T>;
TT bool chmin(T &x,T y){return x>y?(x=y,true):false;}
TT bool chmax(T &x,T y){return x<y?(x=y,true):false;}

struct io_setup{
    io_setup(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout<<fixed<<setprecision(15);
    }
} io_setup;

int main(){
    int N;
    cin>>N;
    vector<int>to(N);
    vector<vector<int>>G(N);
    for(int i=0;i<N;i++){
        int m;
        cin>>m;
        for(int j=0;j<m;j++){
            int a;
            cin>>a;
            a--;
            to[i]++;
            G[i].push_back(a);
        }
    }
    vector<bool>flag(N);
    flag[0]=true;
    queue<int>q;
    q.push(0);
    while(q.size()){
        int x=q.front();
        q.pop();
        for(auto i:G[x]){
            if(!flag[i]){
                flag[i]=true;
                q.push(i);
            }
        }
    }
    for(int i=0;i<N;i++){
        if(!flag[i]){
            cout<<"No\n";
            return 0;
        }
    }
    int cnt=0;
    for(int i=0;i<N;i++){
        if(to[i]==0)cnt++;
    }
    if(cnt<=1)cout<<"Yes\n";
    else cout<<"No\n";
}
0