結果

問題 No.408 五輪ピック
ユーザー 37zigen37zigen
提出日時 2016-08-06 01:54:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 3,728 ms / 5,000 ms
コード長 1,304 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 79,664 KB
実行使用メモリ 61,540 KB
最終ジャッジ日時 2024-04-24 17:18:02
合計ジャッジ時間 39,212 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
40,072 KB
testcase_01 AC 108 ms
40,404 KB
testcase_02 AC 113 ms
41,136 KB
testcase_03 AC 113 ms
41,216 KB
testcase_04 AC 110 ms
41,076 KB
testcase_05 AC 2,586 ms
60,592 KB
testcase_06 AC 684 ms
51,276 KB
testcase_07 AC 860 ms
59,052 KB
testcase_08 AC 1,283 ms
59,200 KB
testcase_09 AC 877 ms
54,268 KB
testcase_10 AC 721 ms
54,772 KB
testcase_11 AC 656 ms
51,336 KB
testcase_12 AC 916 ms
59,452 KB
testcase_13 AC 2,392 ms
60,588 KB
testcase_14 AC 496 ms
49,500 KB
testcase_15 AC 2,595 ms
60,532 KB
testcase_16 AC 2,218 ms
60,932 KB
testcase_17 AC 1,199 ms
61,240 KB
testcase_18 AC 1,150 ms
60,936 KB
testcase_19 AC 1,071 ms
61,036 KB
testcase_20 AC 515 ms
49,704 KB
testcase_21 AC 510 ms
49,052 KB
testcase_22 AC 782 ms
51,040 KB
testcase_23 AC 3,728 ms
61,540 KB
testcase_24 AC 1,683 ms
60,832 KB
testcase_25 AC 1,605 ms
60,480 KB
testcase_26 AC 999 ms
61,428 KB
testcase_27 AC 1,801 ms
60,280 KB
testcase_28 AC 1,357 ms
60,348 KB
testcase_29 AC 1,526 ms
60,212 KB
testcase_30 AC 108 ms
40,264 KB
testcase_31 AC 117 ms
41,392 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 < 200; 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