結果

問題 No.2780 The Bottle Imp
ユーザー 👑 kmjpkmjp
提出日時 2024-06-07 23:00:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 2,146 bytes
コンパイル時間 3,080 ms
コンパイル使用メモリ 219,492 KB
実行使用メモリ 124,760 KB
最終ジャッジ日時 2024-06-08 10:37:16
合計ジャッジ時間 8,584 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
100,736 KB
testcase_01 AC 64 ms
100,736 KB
testcase_02 AC 62 ms
100,608 KB
testcase_03 AC 73 ms
100,608 KB
testcase_04 AC 65 ms
100,608 KB
testcase_05 AC 63 ms
100,736 KB
testcase_06 AC 62 ms
100,736 KB
testcase_07 AC 121 ms
107,904 KB
testcase_08 AC 118 ms
107,904 KB
testcase_09 AC 118 ms
107,904 KB
testcase_10 AC 119 ms
107,904 KB
testcase_11 AC 116 ms
107,904 KB
testcase_12 AC 148 ms
115,176 KB
testcase_13 AC 148 ms
115,296 KB
testcase_14 AC 98 ms
103,680 KB
testcase_15 AC 94 ms
103,528 KB
testcase_16 AC 91 ms
103,424 KB
testcase_17 AC 89 ms
103,552 KB
testcase_18 AC 89 ms
103,552 KB
testcase_19 AC 87 ms
103,424 KB
testcase_20 AC 86 ms
103,392 KB
testcase_21 AC 90 ms
103,424 KB
testcase_22 AC 84 ms
103,168 KB
testcase_23 AC 92 ms
103,296 KB
testcase_24 AC 114 ms
106,624 KB
testcase_25 AC 140 ms
111,096 KB
testcase_26 AC 109 ms
105,216 KB
testcase_27 AC 78 ms
106,752 KB
testcase_28 AC 75 ms
106,752 KB
testcase_29 AC 81 ms
107,264 KB
testcase_30 AC 76 ms
105,984 KB
testcase_31 AC 111 ms
113,020 KB
testcase_32 AC 61 ms
102,528 KB
testcase_33 AC 113 ms
117,344 KB
testcase_34 AC 137 ms
124,760 KB
testcase_35 AC 62 ms
102,016 KB
testcase_36 AC 53 ms
100,608 KB
testcase_37 AC 53 ms
100,608 KB
testcase_38 AC 62 ms
102,144 KB
testcase_39 AC 91 ms
111,604 KB
testcase_40 AC 92 ms
111,600 KB
testcase_41 AC 107 ms
111,592 KB
testcase_42 AC 54 ms
100,736 KB
testcase_43 AC 53 ms
100,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
int M[101010];
vector<int> A[101010];
int vis[101010];

class SCC {
public:
	static const int MV = 2025000;
	vector<vector<int> > SC; int NV,GR[MV];
private:
	vector<int> E[MV], RE[MV], NUM; int vis[MV];
public:
	void init(int NV) { this->NV=NV; for(int i=0;i<NV;i++) { E[i].clear(); RE[i].clear();}}
	void add_edge(int x,int y) { E[x].push_back(y); RE[y].push_back(x); }
	void dfs(int cu) { vis[cu]=1; for(int i=0;i<E[cu].size();i++) if(!vis[E[cu][i]]) dfs(E[cu][i]); NUM.push_back(cu); }
	void revdfs(int cu, int ind) { int i; vis[cu]=1; GR[cu]=ind; SC[ind].push_back(cu);
		FOR(i,RE[cu].size()) if(!vis[RE[cu][i]]) revdfs(RE[cu][i],ind);}
	void scc() {
		int c=0,i; SC.clear(); SC.resize(NV); NUM.clear();
		assert(NV);
		FOR(i,NV) vis[i]=0; FOR(i,NV) if(!vis[i]) dfs(i); FOR(i,NV) vis[i]=0;
		for(int i=NUM.size()-1;i>=0;i--) if(!vis[NUM[i]]){
			SC[c].clear(); revdfs(NUM[i],c); sort(SC[c].begin(),SC[c].end()); c++;
		}
		SC.resize(c);
	}
};
SCC scc;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	scc.init(N);
	FOR(i,N) {
		cin>>M[i];
		FOR(j,M[i]) {
			cin>>x;
			A[i].push_back(x-1);
			scc.add_edge(i,x-1);
		}
	}
	scc.scc();
	set<int> S;
	FOR(i,N) FORR(e,A[i]) if(scc.GR[i]+1==scc.GR[e]) S.insert(scc.GR[i]);
	
	if(S.size()+1==scc.SC.size()&&scc.GR[0]==0) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0