結果

問題 No.806 木を道に
ユーザー rlangevinrlangevin
提出日時 2023-01-03 17:34:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 427 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 156,288 KB
最終ジャッジ日時 2024-05-05 07:33:14
合計ジャッジ時間 4,310 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
51,840 KB
testcase_01 AC 37 ms
52,096 KB
testcase_02 AC 36 ms
52,352 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 35 ms
52,352 KB
testcase_09 AC 35 ms
51,968 KB
testcase_10 AC 111 ms
79,872 KB
testcase_11 AC 98 ms
78,720 KB
testcase_12 WA -
testcase_13 AC 169 ms
85,376 KB
testcase_14 AC 195 ms
86,528 KB
testcase_15 AC 161 ms
86,528 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 107 ms
79,232 KB
testcase_20 AC 161 ms
85,120 KB
testcase_21 AC 140 ms
82,048 KB
testcase_22 AC 203 ms
88,576 KB
testcase_23 AC 188 ms
88,704 KB
testcase_24 AC 155 ms
126,464 KB
testcase_25 AC 215 ms
156,288 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**7)

def dfs(s, p=-1):
    val = 0
    for u in G[s]:
        if u == p:
            continue
        val += dfs(u, s) + 1
    val -= 1
    return max(0, val)

N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, readline().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)
print(max(0, dfs(0)-1))
    
0