結果
問題 | No.806 木を道に |
ユーザー |
![]() |
提出日時 | 2019-03-22 21:52:23 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 720 ms / 2,000 ms |
コード長 | 625 bytes |
コンパイル時間 | 1,915 ms |
コンパイル使用メモリ | 74,260 KB |
実行使用メモリ | 53,340 KB |
最終ジャッジ日時 | 2024-09-19 05:14:50 |
合計ジャッジ時間 | 14,258 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
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();}}