結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー CuriousFairy315CuriousFairy315
提出日時 2020-01-31 22:06:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,418 bytes
コンパイル時間 3,504 ms
コンパイル使用メモリ 79,128 KB
実行使用メモリ 86,924 KB
最終ジャッジ日時 2023-10-17 09:56:15
合計ジャッジ時間 14,539 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
57,108 KB
testcase_01 AC 126 ms
57,440 KB
testcase_02 AC 125 ms
57,520 KB
testcase_03 AC 127 ms
57,768 KB
testcase_04 AC 126 ms
57,500 KB
testcase_05 AC 126 ms
57,668 KB
testcase_06 AC 126 ms
57,364 KB
testcase_07 AC 135 ms
57,608 KB
testcase_08 AC 147 ms
57,644 KB
testcase_09 AC 144 ms
57,644 KB
testcase_10 WA -
testcase_11 AC 151 ms
57,708 KB
testcase_12 AC 142 ms
55,320 KB
testcase_13 AC 323 ms
62,084 KB
testcase_14 AC 340 ms
62,156 KB
testcase_15 AC 343 ms
62,260 KB
testcase_16 AC 327 ms
61,368 KB
testcase_17 AC 352 ms
62,020 KB
testcase_18 AC 518 ms
64,472 KB
testcase_19 WA -
testcase_20 AC 610 ms
66,792 KB
testcase_21 AC 784 ms
75,852 KB
testcase_22 AC 874 ms
85,212 KB
testcase_23 AC 1,038 ms
85,680 KB
testcase_24 AC 944 ms
86,260 KB
testcase_25 AC 1,004 ms
86,924 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 (ArrayList<?> i : graph) cycleCheck &= i.size() == 2;
            if (cycleCheck) ++ count;
            System.out.println(count < N ? "Alice" : "Bob");
        }
    }
}
0