結果

問題 No.1928 Make a Binary Tree
ユーザー akasia_midoriakasia_midori
提出日時 2022-05-06 22:07:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 714 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 303,156 KB
最終ジャッジ日時 2023-09-20 03:02:34
合計ジャッジ時間 27,759 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,312 KB
testcase_01 AC 72 ms
71,308 KB
testcase_02 AC 70 ms
71,444 KB
testcase_03 AC 72 ms
71,416 KB
testcase_04 AC 71 ms
71,388 KB
testcase_05 AC 71 ms
71,416 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 609 ms
211,248 KB
testcase_37 WA -
testcase_38 AC 71 ms
71,148 KB
testcase_39 AC 756 ms
210,364 KB
testcase_40 AC 761 ms
211,680 KB
testcase_41 AC 760 ms
210,916 KB
testcase_42 AC 774 ms
209,924 KB
testcase_43 AC 764 ms
211,220 KB
testcase_44 AC 767 ms
210,440 KB
testcase_45 AC 762 ms
210,816 KB
testcase_46 AC 770 ms
210,380 KB
testcase_47 AC 756 ms
210,388 KB
testcase_48 AC 763 ms
211,248 KB
testcase_49 AC 730 ms
303,156 KB
testcase_50 AC 759 ms
139,208 KB
testcase_51 AC 723 ms
139,084 KB
testcase_52 AC 696 ms
139,220 KB
testcase_53 AC 708 ms
139,312 KB
testcase_54 AC 724 ms
139,380 KB
testcase_55 AC 644 ms
219,048 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 524 ms
148,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

input_count = 0
N  = many_int()[0]

G = {i+1:[] for i in range(N)}

for i in range(N-1):
    x,y = many_int()
    G[x].append(y)
    G[y].append(x)

def dfs(node, old_node):
    global G
    now_dim = max(dim_num[node]-2, 0)
    amari = 0
    
    for next_node in G[node]:
        if old_node!=next_node:
            amari += dfs(next_node, node)
            
    if dim_num[node]==1:
        dim_num[node] += 1
        return now_dim + amari -1
    else:
        return now_dim + amari

dim_num = {k:len(v)-1 for k, v in G.items()}

dim_num[1] += 1

print(N-max(dfs(1, -1), 0))
0