結果

問題 No.806 木を道に
ユーザー ameame
提出日時 2019-03-22 21:52:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 750 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 3,911 ms
コンパイル使用メモリ 73,980 KB
実行使用メモリ 68,168 KB
最終ジャッジ日時 2023-10-19 09:01:58
合計ジャッジ時間 15,125 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,432 KB
testcase_01 AC 130 ms
57,268 KB
testcase_02 AC 142 ms
57,772 KB
testcase_03 AC 139 ms
57,720 KB
testcase_04 AC 131 ms
57,500 KB
testcase_05 AC 144 ms
57,624 KB
testcase_06 AC 141 ms
57,680 KB
testcase_07 AC 134 ms
57,400 KB
testcase_08 AC 132 ms
57,644 KB
testcase_09 AC 133 ms
57,496 KB
testcase_10 AC 405 ms
61,760 KB
testcase_11 AC 399 ms
62,024 KB
testcase_12 AC 679 ms
66,464 KB
testcase_13 AC 579 ms
63,640 KB
testcase_14 AC 646 ms
66,452 KB
testcase_15 AC 655 ms
66,500 KB
testcase_16 AC 457 ms
62,040 KB
testcase_17 AC 631 ms
65,924 KB
testcase_18 AC 295 ms
61,432 KB
testcase_19 AC 419 ms
61,992 KB
testcase_20 AC 667 ms
65,492 KB
testcase_21 AC 527 ms
62,016 KB
testcase_22 AC 750 ms
67,596 KB
testcase_23 AC 713 ms
68,168 KB
testcase_24 AC 543 ms
62,160 KB
testcase_25 AC 638 ms
66,360 KB
testcase_26 AC 437 ms
62,008 KB
testcase_27 AC 708 ms
66,788 KB
testcase_28 AC 229 ms
60,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] cnt = new int[n + 1];
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (cnt[a] < 2) {
                cnt[a]++;
            } else {
                ans++;
            }
            if (cnt[b] < 2) {
                cnt[b]++;
            } else {
                ans++;
            }
        }
        System.out.println(ans);
        sc.close();
    }
}
0