結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ks2mks2m
提出日時 2020-01-31 21:47:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,120 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 78,384 KB
実行使用メモリ 77,504 KB
最終ジャッジ日時 2023-10-17 09:10:55
合計ジャッジ時間 7,907 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,548 KB
testcase_01 AC 54 ms
53,544 KB
testcase_02 AC 53 ms
53,552 KB
testcase_03 AC 54 ms
53,548 KB
testcase_04 AC 53 ms
53,544 KB
testcase_05 AC 53 ms
53,548 KB
testcase_06 AC 53 ms
53,540 KB
testcase_07 AC 54 ms
53,548 KB
testcase_08 AC 56 ms
53,556 KB
testcase_09 AC 56 ms
53,556 KB
testcase_10 WA -
testcase_11 AC 55 ms
51,516 KB
testcase_12 AC 55 ms
53,560 KB
testcase_13 AC 146 ms
58,440 KB
testcase_14 AC 149 ms
58,480 KB
testcase_15 AC 156 ms
58,916 KB
testcase_16 AC 149 ms
58,460 KB
testcase_17 AC 149 ms
59,600 KB
testcase_18 AC 238 ms
61,368 KB
testcase_19 WA -
testcase_20 AC 265 ms
64,708 KB
testcase_21 AC 319 ms
67,004 KB
testcase_22 AC 434 ms
72,724 KB
testcase_23 AC 516 ms
77,504 KB
testcase_24 AC 529 ms
73,636 KB
testcase_25 AC 509 ms
77,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		List<List<Integer>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			sa = br.readLine().split(" ");
			int u = Integer.parseInt(sa[0]);
			int v = Integer.parseInt(sa[1]);
			list.get(u).add(v);
			list.get(v).add(u);
		}
		br.close();

		if (n <= 4) {
			System.out.println("Bob");
			return;
		}
		boolean[] visit = new boolean[n];
		dfs(visit, list, 0);
		for (int i = 0; i < visit.length; i++) {
			if (!visit[i]) {
				System.out.println("Alice");
				return;
			}
		}
		System.out.println("Bob");
	}

	static void dfs(boolean[] visit, List<List<Integer>> list, int x) {
		visit[x] = true;
		for (int c : list.get(x)) {
			if (!visit[c]) {
				dfs(visit, list, c);
			}
		}
	}
}
0