結果

問題 No.408 五輪ピック
ユーザー kei
提出日時 2016-11-04 21:11:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 783 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 82,776 KB
実行使用メモリ 1,075,932 KB
最終ジャッジ日時 2024-11-25 02:59:44
合計ジャッジ時間 70,823 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 5 MLE * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define INF 1<<30
using namespace std;
bool Ans = false;
int N, M;
void dfs(vector<vector<int>> v,int prev,int next,int n) {

	//cout << "next = " << next << " n = " << n << endl;

	if (n == N) { return ; }
	for (int i = 0; i < v[next].size();i++) {
		int f = v[next][i];
		if (f == 1 && n + 1 == N) {
			Ans = true;
		}
		if (f != 1 && f != prev) dfs(v,next, f, n + 1);
	}
	return ;
}

int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	cin >> N >> M;
	vector< vector<int>> v(N + 1);
	for (int i = 0; i < M;i++) {
		int a, b; cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(v,0, 1, 0);
	if (Ans) {
		cout << "YES";
	}
	else { cout << "NO"; }
	cout << endl;
	return 0;
}
0