結果

問題 No.806 木を道に
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-24 08:58:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 817 ms / 2,000 ms
コード長 446 bytes
コンパイル時間 3,400 ms
コンパイル使用メモリ 74,828 KB
実行使用メモリ 53,676 KB
最終ジャッジ日時 2024-04-21 16:03:15
合計ジャッジ時間 16,145 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
41,080 KB
testcase_01 AC 125 ms
41,272 KB
testcase_02 AC 137 ms
41,556 KB
testcase_03 AC 149 ms
41,500 KB
testcase_04 AC 128 ms
41,304 KB
testcase_05 AC 146 ms
41,472 KB
testcase_06 AC 147 ms
41,440 KB
testcase_07 AC 130 ms
41,128 KB
testcase_08 AC 131 ms
41,440 KB
testcase_09 AC 130 ms
41,216 KB
testcase_10 AC 443 ms
48,008 KB
testcase_11 AC 417 ms
47,908 KB
testcase_12 AC 740 ms
52,440 KB
testcase_13 AC 692 ms
48,620 KB
testcase_14 AC 734 ms
52,204 KB
testcase_15 AC 753 ms
52,656 KB
testcase_16 AC 536 ms
48,336 KB
testcase_17 AC 664 ms
51,744 KB
testcase_18 AC 290 ms
46,932 KB
testcase_19 AC 485 ms
48,172 KB
testcase_20 AC 714 ms
51,472 KB
testcase_21 AC 606 ms
48,148 KB
testcase_22 AC 817 ms
53,080 KB
testcase_23 AC 807 ms
53,272 KB
testcase_24 AC 540 ms
48,168 KB
testcase_25 AC 615 ms
53,676 KB
testcase_26 AC 486 ms
48,032 KB
testcase_27 AC 768 ms
52,312 KB
testcase_28 AC 231 ms
45,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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