結果

問題 No.2780 The Bottle Imp
ユーザー Y.Y.Y.Y.
提出日時 2024-06-07 22:49:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,159 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 124,744 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-06-08 10:36:02
合計ジャッジ時間 3,488 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
5,376 KB
testcase_07 AC 35 ms
5,888 KB
testcase_08 AC 35 ms
5,888 KB
testcase_09 AC 36 ms
5,888 KB
testcase_10 AC 36 ms
5,888 KB
testcase_11 AC 34 ms
5,888 KB
testcase_12 AC 52 ms
7,680 KB
testcase_13 AC 51 ms
7,680 KB
testcase_14 AC 30 ms
5,376 KB
testcase_15 AC 32 ms
5,376 KB
testcase_16 AC 31 ms
5,376 KB
testcase_17 AC 31 ms
5,376 KB
testcase_18 AC 31 ms
5,376 KB
testcase_19 AC 32 ms
5,376 KB
testcase_20 AC 32 ms
5,376 KB
testcase_21 AC 32 ms
5,376 KB
testcase_22 AC 15 ms
5,376 KB
testcase_23 AC 25 ms
5,376 KB
testcase_24 AC 29 ms
5,504 KB
testcase_25 AC 44 ms
6,784 KB
testcase_26 AC 30 ms
5,376 KB
testcase_27 AC 27 ms
6,136 KB
testcase_28 AC 27 ms
6,008 KB
testcase_29 WA -
testcase_30 AC 22 ms
5,504 KB
testcase_31 AC 51 ms
8,320 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 52 ms
8,704 KB
testcase_34 AC 52 ms
8,656 KB
testcase_35 AC 17 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 WA -
testcase_38 AC 16 ms
5,376 KB
testcase_39 AC 44 ms
7,400 KB
testcase_40 AC 45 ms
7,404 KB
testcase_41 AC 43 ms
7,148 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define MAX_LL (1LL<<62)
#define MOD 998244353

ll max(const ll &a, const ll &b) {if(a>b) return a; else return b;}
ll min(const ll &a, const ll &b) {if(a<b) return a; else return b;}
ll calc_gcd(ll a, ll b) {while(true){if(a*b == 0) return a+b; else if(a>b) a %= b; else b %= a;}}
ull pow_mod(ull a, ull b, ull mod=-1) {if(mod<2) return 0; ull ans=1, now=a; while(b>0){if(b%2) ans=(ans*now)%mod; now=(now*now)%mod; b/=2;} return ans;}

bool update_max(ll &a, const ll &b) {if(a<b){a=b; return true;} else return false;}
bool update_max(ld &a, const ld &b) {if(a<b){a=b; return true;} else return false;}
bool update_min(ll &a, const ll &b) {if(a>b){a=b; return true;} else return false;}
bool update_min(ld &a, const ld &b) {if(a>b){a=b; return true;} else return false;}

ll upper_char_to_ll(const char &c) {return ll(c)-65;}

int main() {
  ll N;
  cin >> N;

  vector<vector<ll>> A(N);

  ll espar = 0;
  
  for(ll i=0; i<N; i++){
    ll M; cin >> M;
    if(M == 0)
      espar++;
    for(ll j=0; j<M; j++){
      ll temp; cin >> temp; A[i].push_back(temp-1);
    }
  }

  if(espar>=2){
    cout << "No" << endl;
    return 0;
  }
  
  vector<bool> is_reached(N);
  ll reached_counter = 0;
  queue<ll> reached_queue;

  reached_queue.push(0);
  is_reached[0] = true;
  reached_counter++;

  while(!reached_queue.empty()){
    ll next_sacrifice = reached_queue.front();
    //cout << next_sacrifice << ": " << endl;
    reached_queue.pop();
    for(ll i=0; i<A[next_sacrifice].size(); i++){
      if(is_reached[A[next_sacrifice][i]])
        continue;

      //cout << A[next_sacrifice][i] << " ";

      reached_queue.push(A[next_sacrifice][i]);
      is_reached[A[next_sacrifice][i]] = true;
      reached_counter++;
    }
    //cout << endl;
  }

  if(reached_counter >= N)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
0