結果

問題 No.1582 Vertexes vs Edges
ユーザー H3PO4H3PO4
提出日時 2023-07-16 09:37:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 478 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 11,844 KB
実行使用メモリ 36,228 KB
最終ジャッジ日時 2023-10-17 14:54:10
合計ジャッジ時間 9,519 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
9,992 KB
testcase_01 AC 31 ms
9,992 KB
testcase_02 AC 30 ms
9,992 KB
testcase_03 AC 29 ms
9,996 KB
testcase_04 AC 39 ms
10,760 KB
testcase_05 AC 303 ms
33,288 KB
testcase_06 AC 41 ms
11,008 KB
testcase_07 AC 68 ms
13,280 KB
testcase_08 AC 167 ms
21,448 KB
testcase_09 AC 283 ms
31,996 KB
testcase_10 AC 192 ms
23,852 KB
testcase_11 AC 48 ms
11,352 KB
testcase_12 AC 135 ms
19,360 KB
testcase_13 AC 230 ms
24,640 KB
testcase_14 AC 236 ms
24,808 KB
testcase_15 AC 320 ms
30,300 KB
testcase_16 AC 166 ms
19,904 KB
testcase_17 AC 227 ms
24,152 KB
testcase_18 AC 355 ms
34,884 KB
testcase_19 AC 220 ms
25,452 KB
testcase_20 AC 219 ms
23,192 KB
testcase_21 AC 199 ms
21,944 KB
testcase_22 AC 313 ms
32,184 KB
testcase_23 AC 139 ms
17,784 KB
testcase_24 AC 77 ms
13,648 KB
testcase_25 AC 197 ms
21,280 KB
testcase_26 AC 152 ms
18,640 KB
testcase_27 AC 351 ms
29,852 KB
testcase_28 AC 113 ms
15,932 KB
testcase_29 AC 283 ms
26,772 KB
testcase_30 AC 177 ms
20,680 KB
testcase_31 AC 294 ms
27,020 KB
testcase_32 AC 129 ms
17,520 KB
testcase_33 AC 462 ms
36,228 KB
testcase_34 AC 478 ms
36,040 KB
testcase_35 AC 460 ms
36,224 KB
testcase_36 AC 28 ms
9,992 KB
testcase_37 AC 28 ms
9,992 KB
testcase_38 AC 28 ms
9,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

input = sys.stdin.buffer.readline
N = int(input())
T = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = (int(x) - 1 for x in input().split())
    T[a].append(b)
    T[b].append(a)

d = deque([0])
nonvisited = [True] * N
nonvisited[0] = False
bfs_order = []
while d:
    v = d.popleft()
    for x in T[v]:
        if nonvisited[x]:
            nonvisited[x] = False
            d.append(x)
            bfs_order.append((x, v))

dp_black = [0] * N
dp_white = [1] * N
for v, parent in reversed(bfs_order):
    dp_black[parent] += max(dp_black[v], dp_white[v])
    dp_white[parent] += dp_black[v]
print(N - max(dp_white[0], dp_black[0]))
0