結果

問題 No.2780 The Bottle Imp
ユーザー Y.Y.Y.Y.
提出日時 2024-06-14 06:40:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,155 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 133,928 KB
実行使用メモリ 30,576 KB
最終ジャッジ日時 2024-06-14 06:40:58
合計ジャッジ時間 5,429 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 36 ms
7,292 KB
testcase_15 AC 37 ms
7,432 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 38 ms
7,304 KB
testcase_19 AC 36 ms
7,300 KB
testcase_20 AC 36 ms
7,300 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 32 ms
7,576 KB
testcase_28 AC 32 ms
7,576 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 55 ms
11,408 KB
testcase_32 AC 23 ms
6,940 KB
testcase_33 AC 72 ms
26,284 KB
testcase_34 AC 81 ms
30,576 KB
testcase_35 AC 20 ms
6,940 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 19 ms
6,940 KB
testcase_39 AC 55 ms
14,484 KB
testcase_40 AC 56 ms
14,612 KB
testcase_41 WA -
testcase_42 AC 2 ms
6,944 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/scc>

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
//#define MOD 1000000007

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

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;}

int main() {
  ll N;
  cin >> N;
  
  vector<vector<ll>> A(N);
  for(ll i=0; i<N; i++){
  	ll M;
  	cin >> M;
  	for(ll j=0; j<M; j++){
  		ll temp;
  		cin >> temp;
  		A[i].push_back(temp);
  	}
  }
  
  atcoder::scc_graph graph(N);
  for(ll i=0; i<N; i++){
  	for(ll j=0; j<A[i].size(); j++){
  		graph.add_edge(i, A[i][j]-1);
  	}
  }
  
  vector<vector<int>> scc = graph.scc();
  vector<ll> topological(N);
  
  for(ll i=0; i<scc.size(); i++){
  	for(ll j=0; j<scc[i].size(); j++){
  		topological[scc[i][j]] = i;
  	}
  }

  if(topological[0] != 0){
  	cout << "No 1" << endl;
  	return 0;
  }
  
  for(ll i=0; i<scc.size()-1; i++){
  	for(ll j=0; j<scc[i].size(); j++){
  		for(ll k=0; k<A[scc[i][j]].size(); k++){
  			if(topological[A[scc[i][j]][k]-1] == i+1)
  				goto next;
  		}
  		if(j == scc[i].size()-1){
  			cout << "No 2" << endl;
  			return 0;
  		}
  	}
  	next:;
  }
  
  cout << "Yes" << endl;
  return 0;
}
0