結果
| 問題 |
No.3340 Simple Graph Game
|
| コンテスト | |
| ユーザー |
ぽえ
|
| 提出日時 | 2025-11-13 22:21:38 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,498 ms / 2,000 ms |
| コード長 | 2,570 bytes |
| コンパイル時間 | 2,032 ms |
| コンパイル使用メモリ | 82,040 KB |
| 実行使用メモリ | 104,624 KB |
| 最終ジャッジ日時 | 2025-11-18 10:38:55 |
| 合計ジャッジ時間 | 37,907 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 59 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
ArrayList<Integer>[] g = new ArrayList[n];
ArrayList<Integer>[] rg = new ArrayList[n];
for (int i=0; i<n; i++) {
g[i] = new ArrayList<>();
rg[i] = new ArrayList<>();
}
int out[] = new int[n];
for (int i=0; i<m; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
x--; y--;
g[x].add(y);
rg[y].add(x);
out[x]++;
}
int[] alice = new int[n];
int[] bob = new int[n];
int[] alicecnt = new int[n];
int[] bobcnt = new int[n];
for (int i=0; i<n; i++) {
alicecnt[i] = out[i];
bobcnt[i] = out[i];
}
ArrayDeque<Integer> q = new ArrayDeque<>();
for (int i=0; i<n; i++) {
if (out[i] == 0) {
if (alice[i] == 0) { alice[i] = 2; q.add(i*2); }
if (bob[i] == 0) { bob[i] = 2; q.add(i*2+1); }
}
}
while (!q.isEmpty()) {
int cur = q.poll();
int i = cur / 2;
int p = cur % 2;
if (p==0&&alice[i]==2 || p!=0&&bob[i]==2) {
for (int u : rg[i]) {
if (p!=0) {
if (alice[u] == 0) {
alice[u] = 1;
q.add(u*2);
}
} else {
if (bob[u] == 0) {
bob[u] = 1;
q.add(u*2+1);
}
}
}
} else if (p==0&&alice[i]==1 || p!=0&&bob[i]==1) {
for (int u : rg[i]) {
if (p!=0) {
if (alice[u]!=0) continue;
if (--alicecnt[u] == 0) {
alice[u] = 2;
q.add(u*2);
}
} else {
if (bob[u]!=0) continue;
if (--bobcnt[u] == 0) {
bob[u] = 2;
q.add(u*2+1);
}
}
}
}
}
if (alice[0] == 1) System.out.println("Alice");
else if (alice[0] == 2) System.out.println("Bob");
else System.out.println("Draw");
}
}
ぽえ