結果

問題 No.806 木を道に
ユーザー Beat7501Beat7501
提出日時 2019-03-22 21:51:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 503 bytes
コンパイル時間 2,941 ms
コンパイル使用メモリ 83,372 KB
実行使用メモリ 77,060 KB
最終ジャッジ日時 2023-10-19 09:01:23
合計ジャッジ時間 12,048 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
57,232 KB
testcase_01 AC 138 ms
57,224 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 135 ms
57,308 KB
testcase_09 WA -
testcase_10 TLE -
testcase_11 WA -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k[] = new int[n];
		for(int i = 1; i <= n-1; i++){
			k[sc.nextInt()-1]++;
			k[sc.nextInt()-1]++;
		}
		Arrays.sort(k);
		int ans = 0;
		for(int i = 2; i < n-1; i++){
			if(k[i] < 2){
				for(int j = i+1; j < n; j++){
					if(k[j] > 2){
						k[i]++;
						k[j]++;
						ans++;
					}
				}
				Arrays.sort(k);
				i=1;
			}
		}
		System.out.print(ans);
	}
}
0