結果

問題 No.1928 Make a Binary Tree
ユーザー ikomaikoma
提出日時 2022-05-06 23:39:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 627 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 87,816 KB
最終ジャッジ日時 2023-09-20 07:06:09
合計ジャッジ時間 16,669 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,300 KB
testcase_01 AC 17 ms
8,340 KB
testcase_02 AC 17 ms
8,316 KB
testcase_03 AC 17 ms
8,184 KB
testcase_04 AC 17 ms
8,188 KB
testcase_05 AC 16 ms
8,184 KB
testcase_06 AC 17 ms
8,388 KB
testcase_07 AC 17 ms
8,208 KB
testcase_08 AC 17 ms
8,348 KB
testcase_09 AC 17 ms
8,260 KB
testcase_10 AC 18 ms
8,276 KB
testcase_11 AC 17 ms
8,280 KB
testcase_12 AC 17 ms
8,268 KB
testcase_13 AC 18 ms
8,216 KB
testcase_14 AC 17 ms
8,256 KB
testcase_15 AC 53 ms
11,744 KB
testcase_16 AC 43 ms
10,856 KB
testcase_17 AC 36 ms
10,208 KB
testcase_18 AC 51 ms
11,564 KB
testcase_19 AC 20 ms
8,592 KB
testcase_20 AC 37 ms
10,412 KB
testcase_21 AC 27 ms
9,268 KB
testcase_22 AC 41 ms
10,748 KB
testcase_23 AC 34 ms
10,088 KB
testcase_24 AC 50 ms
11,496 KB
testcase_25 AC 54 ms
12,060 KB
testcase_26 AC 972 ms
73,784 KB
testcase_27 AC 589 ms
49,312 KB
testcase_28 AC 654 ms
53,076 KB
testcase_29 AC 1,141 ms
83,308 KB
testcase_30 AC 554 ms
46,140 KB
testcase_31 AC 734 ms
58,568 KB
testcase_32 AC 1,107 ms
80,956 KB
testcase_33 AC 611 ms
50,296 KB
testcase_34 AC 734 ms
59,216 KB
testcase_35 AC 806 ms
82,492 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 #

import sys
input = sys.stdin.readline

sys.setrecursionlimit(10 ** 6)


N=int(input())
edge = [[] for _ in range(N)]
XY=[list(map(int,input().split())) for _ in range(N-1)]
for x,y in XY:
    x,y=x-1,y-1
    edge[x].append(y)
    edge[y].append(x)
visit = [0]*N

from heapq import *

def dfs(v=0):
    visit[v]=1
    n_tree = []
    for to in edge[v]:
        if visit[to]:continue
        n,lst = dfs(to)
        heappush(n_tree,-n)
        while lst:
            heappush(n_tree,heappop(lst))
    ret = 1
    for i in range(min(2,len(n_tree))):
        ret += -heappop(n_tree)
    return ret,n_tree

ans,_ = dfs()
print(ans)
0