結果

問題 No.408 五輪ピック
ユーザー hiyokko2hiyokko2
提出日時 2016-08-06 00:11:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,051 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 166,380 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-24 15:36:14
合計ジャッジ時間 8,828 ms
ジャッジサーバーID
(参考情報)
judge5 / 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 24 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 24 ms
5,376 KB
testcase_08 AC 20 ms
5,376 KB
testcase_09 AC 20 ms
5,376 KB
testcase_10 AC 17 ms
5,376 KB
testcase_11 AC 17 ms
5,376 KB
testcase_12 AC 29 ms
5,376 KB
testcase_13 AC 24 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 24 ms
5,376 KB
testcase_16 AC 28 ms
5,376 KB
testcase_17 AC 32 ms
5,376 KB
testcase_18 AC 31 ms
5,376 KB
testcase_19 AC 33 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 15 ms
5,376 KB
testcase_23 AC 32 ms
5,376 KB
testcase_24 WA -
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int N, M;
vector<int> G[2 * 10000];
int A, B;

//i:辺をたどった回数, j:今いる頂点, checked:通った頂点の集合
bool rec(int i, int j, set<int> checked)
{
	/*
	printf("rec(%d, %d, set)\n", i, j);
	set<int>::iterator it = checked.begin();
	while (it != checked.end())
	{
		cout << *it << ", " << endl;
		it++;
	}
	*/

	if (i == 5)
	{
		if (j == 0) return true;
		else return false;
	}

	if (j != 0)
	{
		checked.insert(j);
	}

	bool ret = false;
	rep(ii,G[j].size())
	{
		if (checked.find(G[j][ii]) == checked.end())
		{
			//次の頂点がまだ未探索の場合
			//checked.insert(G[j][i]);
			ret = ret || rec(i + 1, G[j][ii], checked);
			//checked.erase(G[j][i]);
		}
	}

	return ret;
}

signed main()
{
	cin >> N >> M;
	rep(i,M)
	{
		cin >> A >> B;
		A--; B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}

	set<int> checked;
	if (rec(0, 0, checked))
	{
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}
0