結果

問題 No.806 木を道に
ユーザー しめはじめしめはじめ
提出日時 2019-05-29 10:03:34
言語 PHP
(8.3.4)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 563 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 32,672 KB
実行使用メモリ 38,520 KB
最終ジャッジ日時 2023-10-17 18:41:17
合計ジャッジ時間 3,206 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
32,468 KB
testcase_01 AC 44 ms
32,468 KB
testcase_02 AC 44 ms
32,468 KB
testcase_03 AC 44 ms
32,468 KB
testcase_04 AC 43 ms
32,468 KB
testcase_05 AC 44 ms
32,468 KB
testcase_06 AC 43 ms
32,468 KB
testcase_07 AC 44 ms
32,468 KB
testcase_08 AC 43 ms
32,468 KB
testcase_09 AC 44 ms
32,468 KB
testcase_10 AC 56 ms
32,468 KB
testcase_11 AC 55 ms
32,468 KB
testcase_12 AC 97 ms
36,472 KB
testcase_13 AC 80 ms
36,472 KB
testcase_14 AC 92 ms
36,472 KB
testcase_15 AC 97 ms
36,472 KB
testcase_16 AC 63 ms
34,424 KB
testcase_17 AC 89 ms
36,472 KB
testcase_18 AC 48 ms
32,468 KB
testcase_19 AC 57 ms
34,424 KB
testcase_20 AC 88 ms
36,472 KB
testcase_21 AC 68 ms
34,424 KB
testcase_22 AC 106 ms
38,520 KB
testcase_23 AC 106 ms
38,520 KB
testcase_24 AC 69 ms
32,472 KB
testcase_25 AC 83 ms
34,424 KB
testcase_26 AC 61 ms
34,424 KB
testcase_27 AC 99 ms
38,520 KB
testcase_28 AC 44 ms
32,468 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
    $n = trim(fgets(STDIN));
    $node = array();
    $target= array();
    for( $i = 1; $i <= $n; $i++ ){
        $node[$i] = 0;
    }
    $ans = 0;
    for( $i = 0; $i < ( $n - 1 ); $i++ ){
        list( $a, $b ) = sscanf( trim(fgets(STDIN)), "%d %d" );
        $node[$a]++;
        $node[$b]++;
        if ( $node[$a] > 2 ){
            $target[] = $a;
        }
        if ( $node[$b] > 2 ){
            $target[] = $b;
        }
    }
    $target = array_unique( $target );
	foreach( $target as $v ){
        $ans += $node[$v] - 2;
	}
	print $ans."\n";
0