結果

問題 No.408 五輪ピック
ユーザー pekempeypekempey
提出日時 2016-08-14 13:19:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 824 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 161,260 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-25 06:33:55
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,376 KB
testcase_01 AC 6 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 14 ms
5,888 KB
testcase_06 AC 33 ms
5,888 KB
testcase_07 AC 16 ms
6,144 KB
testcase_08 AC 12 ms
5,760 KB
testcase_09 AC 12 ms
5,760 KB
testcase_10 AC 27 ms
6,016 KB
testcase_11 AC 25 ms
5,888 KB
testcase_12 AC 18 ms
6,144 KB
testcase_13 AC 13 ms
5,888 KB
testcase_14 AC 14 ms
5,504 KB
testcase_15 AC 13 ms
5,888 KB
testcase_16 AC 14 ms
5,760 KB
testcase_17 AC 16 ms
6,016 KB
testcase_18 AC 18 ms
6,144 KB
testcase_19 AC 23 ms
6,272 KB
testcase_20 AC 22 ms
5,888 KB
testcase_21 AC 15 ms
5,504 KB
testcase_22 AC 33 ms
5,888 KB
testcase_23 AC 19 ms
6,400 KB
testcase_24 AC 157 ms
6,144 KB
testcase_25 AC 13 ms
6,016 KB
testcase_26 AC 47 ms
6,400 KB
testcase_27 AC 38 ms
5,888 KB
testcase_28 AC 15 ms
5,888 KB
testcase_29 AC 27 ms
5,760 KB
testcase_30 AC 6 ms
5,376 KB
testcase_31 AC 6 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |                 scanf("%d %d", &u, &v);
      |                 ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<int> g[20000];
int color[20000];
int vis[20000][16];

bool dfs(int curr, int c, int s) {
	if (vis[curr][c]) return false;
	vis[curr][c] = true;
	if (curr != s) {
		if (c & 1 << color[curr]) return false;
		c |= 1 << color[curr];
	} else {
		if (c != 0) return c == 15;
	}

	for (int next : g[curr]) {
		if (dfs(next, c, s)) return true;
	}
	return false;
}

int main() {
	int n, m;
	cin >> n >> m;

	srand(time(NULL));

	for (int i = 0; i < m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	for (int i = 0; i < 50; i++) {
		memset(vis, false, sizeof(vis));

		for (int i = 0; i < n; i++) {
			color[i] = rand() % 4;
		}

		if (dfs(0, 0, 0)) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}
0