結果

問題 No.806 木を道に
ユーザー Grenache
提出日時 2019-04-27 16:24:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 818 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 4,706 ms
コンパイル使用メモリ 74,596 KB
実行使用メモリ 53,068 KB
最終ジャッジ日時 2024-11-28 07:54:55
合計ジャッジ時間 19,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder806 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] cnt = new int[n];
		for (int i = 0; i < n - 1; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			
			cnt[a]++;
			cnt[b]++;
		}

		int ans = 0;
		for (int e : cnt) {
			ans += Math.max(0, e - 2);
		}

		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0