結果

問題 No.806 木を道に
ユーザー tentententen
提出日時 2022-08-03 10:43:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 1,190 bytes
コンパイル時間 3,270 ms
コンパイル使用メモリ 73,672 KB
実行使用メモリ 58,216 KB
最終ジャッジ日時 2023-10-10 01:06:34
合計ジャッジ時間 8,242 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,304 KB
testcase_01 AC 43 ms
49,356 KB
testcase_02 AC 46 ms
49,312 KB
testcase_03 AC 44 ms
49,432 KB
testcase_04 AC 44 ms
49,252 KB
testcase_05 AC 45 ms
49,196 KB
testcase_06 AC 43 ms
49,252 KB
testcase_07 AC 44 ms
49,280 KB
testcase_08 AC 45 ms
49,740 KB
testcase_09 AC 44 ms
49,292 KB
testcase_10 AC 142 ms
54,744 KB
testcase_11 AC 144 ms
54,860 KB
testcase_12 AC 228 ms
57,024 KB
testcase_13 AC 192 ms
55,948 KB
testcase_14 AC 231 ms
57,208 KB
testcase_15 AC 233 ms
57,268 KB
testcase_16 AC 156 ms
54,984 KB
testcase_17 AC 227 ms
57,300 KB
testcase_18 AC 120 ms
52,720 KB
testcase_19 AC 143 ms
54,868 KB
testcase_20 AC 221 ms
56,736 KB
testcase_21 AC 180 ms
55,008 KB
testcase_22 AC 249 ms
58,216 KB
testcase_23 AC 250 ms
57,992 KB
testcase_24 AC 190 ms
55,196 KB
testcase_25 AC 210 ms
55,232 KB
testcase_26 AC 151 ms
55,232 KB
testcase_27 AC 234 ms
57,880 KB
testcase_28 AC 101 ms
52,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

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

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0