結果

問題 No.408 五輪ピック
コンテスト
ユーザー pekempey
提出日時 2016-08-14 13:19:11
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 860 ms
コンパイル使用メモリ 180,844 KB
実行使用メモリ 9,992 KB
最終ジャッジ日時 2026-09-20 17:47:54
合計ジャッジ時間 3,989 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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