結果
| 問題 |
No.408 五輪ピック
|
| ユーザー |
|
| 提出日時 | 2016-08-06 01:54:36 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 4,145 ms / 5,000 ms |
| コード長 | 1,304 bytes |
| コンパイル時間 | 2,307 ms |
| コンパイル使用メモリ | 80,160 KB |
| 実行使用メモリ | 71,292 KB |
| 最終ジャッジ日時 | 2024-11-07 02:02:03 |
| 合計ジャッジ時間 | 42,903 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
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");
}
}