結果

問題 No.1928 Make a Binary Tree
ユーザー tnodinotnodino
提出日時 2022-05-07 23:58:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 793 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 84,904 KB
最終ジャッジ日時 2023-09-21 12:12:10
合計ジャッジ時間 16,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,064 KB
testcase_01 AC 15 ms
8,120 KB
testcase_02 AC 17 ms
8,128 KB
testcase_03 AC 17 ms
8,044 KB
testcase_04 AC 15 ms
8,176 KB
testcase_05 AC 16 ms
8,296 KB
testcase_06 AC 15 ms
8,104 KB
testcase_07 AC 16 ms
8,040 KB
testcase_08 AC 16 ms
8,160 KB
testcase_09 AC 16 ms
8,040 KB
testcase_10 AC 16 ms
8,084 KB
testcase_11 AC 15 ms
8,052 KB
testcase_12 AC 16 ms
8,164 KB
testcase_13 AC 15 ms
8,120 KB
testcase_14 AC 16 ms
8,120 KB
testcase_15 AC 74 ms
10,364 KB
testcase_16 AC 49 ms
9,884 KB
testcase_17 AC 38 ms
9,548 KB
testcase_18 AC 58 ms
10,312 KB
testcase_19 AC 20 ms
8,472 KB
testcase_20 AC 40 ms
9,492 KB
testcase_21 AC 28 ms
8,784 KB
testcase_22 AC 45 ms
9,808 KB
testcase_23 AC 37 ms
9,352 KB
testcase_24 AC 56 ms
10,268 KB
testcase_25 AC 63 ms
10,640 KB
testcase_26 AC 1,103 ms
50,928 KB
testcase_27 AC 669 ms
34,668 KB
testcase_28 AC 764 ms
37,292 KB
testcase_29 AC 1,354 ms
56,836 KB
testcase_30 AC 598 ms
32,876 KB
testcase_31 AC 822 ms
41,016 KB
testcase_32 AC 1,304 ms
55,292 KB
testcase_33 AC 669 ms
35,444 KB
testcase_34 AC 821 ms
41,544 KB
testcase_35 AC 897 ms
55,740 KB
testcase_36 TLE -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**6)

from heapq import heappop,heappush

def dfs(pos, pre):
    global Vec
    for nxt in G[pos]:
        if nxt == pre:
            continue
        P = dfs(nxt, pos)
        heappush(Vec[pos], -P)
    for nxt in G[pos]:
        if nxt == pre:
            continue
        while Vec[nxt]:
            heappush(Vec[pos], heappop(Vec[nxt]))
    ret = 1
    if len(Vec[pos]) <= 2:
        while Vec[pos]:
            ret += -heappop(Vec[pos])
    else:
        for _ in range(2):
            ret += -heappop(Vec[pos])
    return ret

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    G[x].append(y)
    G[y].append(x)
Vec = [[] for _ in range(N)]
print(dfs(0, -1))
0