結果

問題 No.408 五輪ピック
ユーザー 37zigen37zigen
提出日時 2016-08-06 01:57:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,848 ms / 5,000 ms
コード長 1,305 bytes
コンパイル時間 2,730 ms
コンパイル使用メモリ 79,992 KB
実行使用メモリ 61,864 KB
最終ジャッジ日時 2024-04-24 17:19:15
合計ジャッジ時間 35,095 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
41,556 KB
testcase_01 AC 132 ms
41,604 KB
testcase_02 AC 139 ms
41,708 KB
testcase_03 AC 141 ms
41,412 KB
testcase_04 AC 135 ms
41,664 KB
testcase_05 AC 1,942 ms
61,164 KB
testcase_06 AC 769 ms
54,292 KB
testcase_07 AC 872 ms
51,564 KB
testcase_08 AC 1,189 ms
60,036 KB
testcase_09 AC 847 ms
51,484 KB
testcase_10 AC 775 ms
50,388 KB
testcase_11 AC 717 ms
51,056 KB
testcase_12 AC 867 ms
53,236 KB
testcase_13 AC 1,821 ms
60,796 KB
testcase_14 AC 514 ms
49,692 KB
testcase_15 AC 1,914 ms
60,660 KB
testcase_16 AC 1,709 ms
61,040 KB
testcase_17 AC 1,159 ms
61,148 KB
testcase_18 AC 1,147 ms
61,152 KB
testcase_19 AC 958 ms
56,896 KB
testcase_20 AC 571 ms
49,892 KB
testcase_21 AC 516 ms
49,192 KB
testcase_22 AC 689 ms
51,140 KB
testcase_23 AC 2,848 ms
61,472 KB
testcase_24 AC 1,413 ms
61,232 KB
testcase_25 AC 1,463 ms
60,492 KB
testcase_26 AC 1,101 ms
61,864 KB
testcase_27 AC 1,435 ms
60,560 KB
testcase_28 AC 1,352 ms
60,192 KB
testcase_29 AC 1,249 ms
60,192 KB
testcase_30 AC 142 ms
41,324 KB
testcase_31 AC 124 ms
40,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package No400番台;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	static void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<Integer>[] e = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			e[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			e[a].add(b);
			e[b].add(a);
		}

		boolean ans = false;
		for (int i = 0; i < 100; i++) {
			Random rand = new Random();
			int[] col = new int[n];
			Arrays.fill(col, -1);
			for (int j = 1; j < n; j++) {
				col[j] = rand.nextInt(4);
			}
			boolean[][] dp = new boolean[1 << 4][n];
			dp[0][0] = true;
			for (int s = 0; s < (1 << 4) - 1; s++) {
				for (int v = 0; v < n; v++) {
					if (dp[s][v]) {
						for (int u : e[v]) {
							if (u != 0) {
								int t = s | (1 << col[u]);
								if (t > s) {
									dp[t][u] = true;
								}
							}
						}
					}
				}
			}
			for (int j = 1; j < n; j++) {
				if (dp[(1 << 4) - 1][j]) {
					for (int v : e[j]) {
						if (v == 0) {
							ans = true;
						}
					}
				}
			}
		}
		System.out.println(ans ? "YES" : "NO");
	}
}
0