結果

問題 No.1805 Approaching Many Typhoon
ユーザー matcharate12
提出日時 2022-01-10 19:42:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 1,831 ms
コンパイル使用メモリ 175,112 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-15 14:58:42
合計ジャッジ時間 2,488 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define all(A) (A).begin(),(A).end()
#define MOD 1000000007
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main(void){
	int n,m,s,g; cin >> n >> m >> s >> g;
	s--; g--;
	vector<vector<int>> G(n);
	rep(i,0,m){
		int f,t; cin >> f >> t;
		f--; t--;
		G[f].push_back(t);
		G[t].push_back(f);
	}
	stack<int> S;
	vector<int> seen(n,0);
	int w; cin >> w;
	rep(i,0,w){
		int a; cin >> a;
		a--;
		seen[a] = 1;
	}

	S.push(s); seen[s] = 1;
	while(!S.empty()){
		int state = S.top(); S.pop();
		for(int s2 : G[state]){
			if(seen[s2]) continue;
			S.push(s2);
			seen[s2] = 1;
		}
	}
	cout << (seen[g] ? "Yes" : "No");
}
0