結果

問題 No.806 木を道に
ユーザー tentententen
提出日時 2020-11-18 14:01:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 928 ms / 2,000 ms
コード長 677 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 73,088 KB
実行使用メモリ 79,496 KB
最終ジャッジ日時 2023-09-30 15:01:32
合計ジャッジ時間 19,070 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,908 KB
testcase_01 AC 122 ms
56,440 KB
testcase_02 AC 134 ms
55,408 KB
testcase_03 AC 132 ms
56,076 KB
testcase_04 AC 126 ms
55,892 KB
testcase_05 AC 142 ms
55,636 KB
testcase_06 AC 134 ms
56,036 KB
testcase_07 AC 126 ms
56,048 KB
testcase_08 AC 123 ms
55,484 KB
testcase_09 AC 125 ms
56,056 KB
testcase_10 AC 423 ms
62,904 KB
testcase_11 AC 413 ms
62,348 KB
testcase_12 AC 845 ms
76,540 KB
testcase_13 AC 690 ms
66,636 KB
testcase_14 AC 838 ms
76,176 KB
testcase_15 AC 843 ms
77,020 KB
testcase_16 AC 524 ms
62,852 KB
testcase_17 AC 786 ms
72,408 KB
testcase_18 AC 290 ms
59,892 KB
testcase_19 AC 437 ms
62,324 KB
testcase_20 AC 789 ms
71,440 KB
testcase_21 AC 577 ms
65,120 KB
testcase_22 AC 928 ms
79,496 KB
testcase_23 AC 891 ms
78,692 KB
testcase_24 AC 564 ms
65,292 KB
testcase_25 AC 689 ms
74,328 KB
testcase_26 AC 456 ms
62,872 KB
testcase_27 AC 788 ms
79,072 KB
testcase_28 AC 223 ms
59,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        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<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        int ans = 0;
        for(ArrayList<Integer> node : graph) {
            ans += Math.max(0, node.size() - 2);
        }
        System.out.println(ans);
    }
}
0