結果

問題 No.1582 Vertexes vs Edges
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-12-16 16:22:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 86,576 KB
実行使用メモリ 90,992 KB
最終ジャッジ日時 2023-10-11 14:31:31
合計ジャッジ時間 10,191 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,204 KB
testcase_01 AC 70 ms
71,108 KB
testcase_02 AC 71 ms
71,120 KB
testcase_03 AC 70 ms
71,148 KB
testcase_04 AC 111 ms
78,132 KB
testcase_05 AC 185 ms
88,972 KB
testcase_06 AC 115 ms
78,276 KB
testcase_07 AC 116 ms
78,568 KB
testcase_08 AC 149 ms
83,484 KB
testcase_09 AC 179 ms
88,624 KB
testcase_10 AC 156 ms
84,816 KB
testcase_11 AC 113 ms
78,360 KB
testcase_12 AC 142 ms
82,568 KB
testcase_13 AC 169 ms
85,280 KB
testcase_14 AC 171 ms
85,536 KB
testcase_15 AC 195 ms
87,980 KB
testcase_16 AC 159 ms
83,064 KB
testcase_17 AC 172 ms
84,960 KB
testcase_18 AC 205 ms
90,048 KB
testcase_19 AC 164 ms
84,732 KB
testcase_20 AC 175 ms
83,864 KB
testcase_21 AC 158 ms
83,592 KB
testcase_22 AC 194 ms
88,548 KB
testcase_23 AC 142 ms
82,044 KB
testcase_24 AC 120 ms
78,656 KB
testcase_25 AC 162 ms
84,188 KB
testcase_26 AC 154 ms
82,692 KB
testcase_27 AC 202 ms
87,212 KB
testcase_28 AC 132 ms
80,440 KB
testcase_29 AC 192 ms
86,600 KB
testcase_30 AC 162 ms
83,284 KB
testcase_31 AC 192 ms
86,828 KB
testcase_32 AC 142 ms
81,480 KB
testcase_33 AC 236 ms
90,992 KB
testcase_34 AC 253 ms
90,468 KB
testcase_35 AC 244 ms
90,992 KB
testcase_36 AC 71 ms
71,172 KB
testcase_37 AC 71 ms
71,228 KB
testcase_38 AC 71 ms
71,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    G[a].append(b)
    G[b].append(a)
dp1, dp2 = [0] * n, [1] * n
def dfs(now, prev):
    if now != 0 and len(G[now]) == 1:
        dp1[now] = 0
        dp2[now] = 1
    for next in G[now]:
        if next != prev:
            dfs(next, now)
            dp1[now] += max(dp1[next], dp2[next])
            dp2[now] += dp1[next]
dfs(0, -1)
print(n - max(dp1[0], dp2[0]))
0