結果

問題 No.1928 Make a Binary Tree
ユーザー ikomaikoma
提出日時 2022-05-06 23:49:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 763 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 87,360 KB
実行使用メモリ 359,280 KB
最終ジャッジ日時 2023-09-20 07:26:57
合計ジャッジ時間 16,861 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,360 KB
testcase_01 AC 81 ms
71,344 KB
testcase_02 WA -
testcase_03 AC 81 ms
71,104 KB
testcase_04 AC 79 ms
71,448 KB
testcase_05 AC 79 ms
71,496 KB
testcase_06 AC 81 ms
71,364 KB
testcase_07 AC 81 ms
71,296 KB
testcase_08 AC 81 ms
71,376 KB
testcase_09 AC 80 ms
71,388 KB
testcase_10 AC 80 ms
71,380 KB
testcase_11 WA -
testcase_12 AC 79 ms
71,416 KB
testcase_13 AC 80 ms
71,408 KB
testcase_14 AC 81 ms
71,260 KB
testcase_15 AC 259 ms
81,348 KB
testcase_16 AC 215 ms
81,436 KB
testcase_17 AC 208 ms
81,264 KB
testcase_18 AC 233 ms
82,376 KB
testcase_19 AC 123 ms
77,900 KB
testcase_20 AC 190 ms
80,892 KB
testcase_21 AC 168 ms
79,664 KB
testcase_22 AC 213 ms
80,396 KB
testcase_23 AC 191 ms
80,248 KB
testcase_24 AC 230 ms
82,172 KB
testcase_25 AC 237 ms
81,768 KB
testcase_26 AC 622 ms
121,864 KB
testcase_27 AC 469 ms
106,168 KB
testcase_28 AC 451 ms
108,788 KB
testcase_29 AC 691 ms
128,124 KB
testcase_30 AC 441 ms
103,208 KB
testcase_31 AC 518 ms
111,148 KB
testcase_32 AC 652 ms
127,380 KB
testcase_33 AC 490 ms
107,124 KB
testcase_34 AC 503 ms
111,780 KB
testcase_35 AC 308 ms
130,148 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,na=0):
    visit[v]=1
    n_tree = []
    if len(edge[v])<2:na+=1
    for to in edge[v]:
        if visit[to]:continue
        n,lst = dfs(to,na)
        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)
    ret_tree = []
    while na and n_tree:
        heappush(ret_tree,heappop(n_tree))
        na-=1
    return ret,n_tree

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