結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー CuriousFairy315CuriousFairy315
提出日時 2020-01-31 22:10:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,184 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 4,260 ms
コンパイル使用メモリ 79,408 KB
実行使用メモリ 86,784 KB
最終ジャッジ日時 2023-10-17 09:59:49
合計ジャッジ時間 14,857 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,528 KB
testcase_01 AC 138 ms
57,480 KB
testcase_02 AC 134 ms
57,532 KB
testcase_03 AC 133 ms
57,732 KB
testcase_04 AC 133 ms
57,476 KB
testcase_05 AC 134 ms
57,604 KB
testcase_06 AC 135 ms
57,572 KB
testcase_07 AC 148 ms
57,544 KB
testcase_08 AC 148 ms
57,308 KB
testcase_09 AC 156 ms
57,572 KB
testcase_10 AC 151 ms
57,588 KB
testcase_11 AC 152 ms
57,604 KB
testcase_12 AC 151 ms
55,716 KB
testcase_13 AC 347 ms
62,320 KB
testcase_14 AC 356 ms
62,352 KB
testcase_15 AC 345 ms
62,032 KB
testcase_16 AC 347 ms
62,084 KB
testcase_17 AC 356 ms
62,216 KB
testcase_18 AC 556 ms
64,400 KB
testcase_19 AC 553 ms
64,636 KB
testcase_20 AC 670 ms
67,944 KB
testcase_21 AC 861 ms
76,428 KB
testcase_22 AC 976 ms
86,256 KB
testcase_23 AC 1,171 ms
85,748 KB
testcase_24 AC 1,094 ms
85,816 KB
testcase_25 AC 1,184 ms
86,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.ArrayDeque;

public class Main {
    public static void main(String[] args) {
        new Main();
    }
    
    public Main() {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
            for (int i = 0;i < N;++ i) graph.add(new ArrayList<>());
            int check = 0;
            for (int i = 1;i < N;++ i) {
                int u = sc.nextInt(), v = sc.nextInt();
                check = u;
                graph.get(u).add(v);
                graph.get(v).add(u);
            }
            ArrayDeque<Integer> bfs = new ArrayDeque<>();
            boolean[] reach = new boolean[N];
            bfs.addLast(check);
            reach[check] = true;
            int count = 1;
            while(!bfs.isEmpty()) {
                int tmp = bfs.removeFirst();
                for (int i : graph.get(tmp)) {
                    if (!reach[i]) {
                        reach[i] = true;
                        bfs.addLast(i);
                        ++ count;
                    }
                }
            }
            boolean cycleCheck = true;
            for (int i = 0;i < N;++ i) cycleCheck &= !reach[i] || graph.get(i).size() == 2;
            if (cycleCheck) ++ count;
            System.out.println(count < N ? "Alice" : "Bob");
        }
    }
}
0