結果

問題 No.806 木を道に
ユーザー htensaihtensai
提出日時 2020-06-10 13:58:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 736 ms / 2,000 ms
コード長 451 bytes
コンパイル時間 4,355 ms
コンパイル使用メモリ 71,764 KB
実行使用メモリ 64,984 KB
最終ジャッジ日時 2023-09-05 07:51:39
合計ジャッジ時間 15,973 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
55,884 KB
testcase_01 AC 125 ms
55,704 KB
testcase_02 AC 135 ms
55,744 KB
testcase_03 AC 135 ms
55,476 KB
testcase_04 AC 125 ms
55,840 KB
testcase_05 AC 142 ms
55,960 KB
testcase_06 AC 135 ms
55,924 KB
testcase_07 AC 126 ms
55,516 KB
testcase_08 AC 126 ms
55,896 KB
testcase_09 AC 125 ms
55,740 KB
testcase_10 AC 390 ms
60,280 KB
testcase_11 AC 411 ms
60,208 KB
testcase_12 AC 665 ms
63,928 KB
testcase_13 AC 567 ms
59,440 KB
testcase_14 AC 653 ms
63,720 KB
testcase_15 AC 666 ms
64,612 KB
testcase_16 AC 450 ms
60,144 KB
testcase_17 AC 608 ms
63,316 KB
testcase_18 AC 282 ms
60,520 KB
testcase_19 AC 425 ms
60,388 KB
testcase_20 AC 691 ms
62,324 KB
testcase_21 AC 501 ms
60,388 KB
testcase_22 AC 733 ms
64,984 KB
testcase_23 AC 736 ms
64,792 KB
testcase_24 AC 528 ms
60,552 KB
testcase_25 AC 617 ms
63,032 KB
testcase_26 AC 433 ms
60,104 KB
testcase_27 AC 685 ms
64,936 KB
testcase_28 AC 211 ms
59,036 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[] counts = new int[n];
		for (int i = 0; i < n - 1; i++) {
		    int a = sc.nextInt() - 1;
		    int b = sc.nextInt() - 1;
		    counts[a]++;
		    counts[b]++;
		}
		int total = 0;
		for (int x : counts) {
		    if (x > 2) {
		        total += x - 2;
		    }
		}
		System.out.println(total);
	}
}
0