結果

問題 No.1928 Make a Binary Tree
ユーザー ikomaikoma
提出日時 2022-05-06 22:25:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,006 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 355,672 KB
最終ジャッジ日時 2023-09-20 03:25:16
合計ジャッジ時間 12,912 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,816 KB
testcase_01 AC 76 ms
71,752 KB
testcase_02 AC 78 ms
71,516 KB
testcase_03 AC 76 ms
71,364 KB
testcase_04 AC 78 ms
71,684 KB
testcase_05 AC 76 ms
71,584 KB
testcase_06 WA -
testcase_07 AC 77 ms
71,436 KB
testcase_08 AC 79 ms
71,580 KB
testcase_09 AC 75 ms
71,736 KB
testcase_10 AC 76 ms
71,576 KB
testcase_11 AC 75 ms
71,220 KB
testcase_12 AC 73 ms
71,168 KB
testcase_13 WA -
testcase_14 AC 76 ms
71,740 KB
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 AC 288 ms
128,204 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)
if "pypyjit" in sys.builtin_module_names:
    import pypyjit
    pypyjit.set_param("max_unroll_recursion=-1")

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

dnode = []
from heapq import *

def dfs(v=0):
    visit[v]=1
    n_tree = []
    del_lst = []
    for to in edge[v]:
        if visit[to]:continue
        n,lst = dfs(to)
        n_tree.append(n)
        del_lst.extend(lst)
    if len(n_tree)==0:
        return 1,[]
    if len(n_tree)==1:
        if del_lst:
            heapify(del_lst)
            n = -heappop(del_lst)
        else: n=0
        return n+n_tree[0]+1,del_lst
    if len(n_tree)<=2:

        return sum(n_tree)+1,del_lst
    n_tree.sort(reverse=True)
    for i in n_tree[2:]:
        del_lst.append(-i)
    return sum(n_tree[:2])+1,del_lst

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