結果

問題 No.806 木を道に
ユーザー rlangevinrlangevin
提出日時 2023-01-03 17:34:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 427 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 159,724 KB
最終ジャッジ日時 2023-08-18 00:42:52
合計ジャッジ時間 6,022 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,436 KB
testcase_01 AC 74 ms
71,368 KB
testcase_02 AC 74 ms
71,384 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 73 ms
71,332 KB
testcase_09 AC 73 ms
71,328 KB
testcase_10 AC 153 ms
84,124 KB
testcase_11 AC 136 ms
84,000 KB
testcase_12 WA -
testcase_13 AC 219 ms
88,796 KB
testcase_14 AC 255 ms
99,664 KB
testcase_15 AC 214 ms
93,024 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 142 ms
83,792 KB
testcase_20 AC 212 ms
91,376 KB
testcase_21 AC 184 ms
87,604 KB
testcase_22 AC 240 ms
95,460 KB
testcase_23 AC 240 ms
96,208 KB
testcase_24 AC 181 ms
127,756 KB
testcase_25 AC 241 ms
159,724 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