結果

問題 No.1928 Make a Binary Tree
ユーザー 👑 rin204rin204
提出日時 2022-05-06 21:45:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,293 ms / 3,000 ms
コード長 811 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 394,452 KB
最終ジャッジ日時 2023-09-20 02:37:14
合計ジャッジ時間 35,631 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,456 KB
testcase_01 AC 78 ms
71,516 KB
testcase_02 AC 78 ms
71,668 KB
testcase_03 AC 76 ms
71,260 KB
testcase_04 AC 77 ms
71,380 KB
testcase_05 AC 78 ms
71,396 KB
testcase_06 AC 77 ms
71,572 KB
testcase_07 AC 78 ms
71,644 KB
testcase_08 AC 77 ms
71,420 KB
testcase_09 AC 78 ms
71,512 KB
testcase_10 AC 77 ms
71,464 KB
testcase_11 AC 75 ms
71,616 KB
testcase_12 AC 76 ms
71,676 KB
testcase_13 AC 76 ms
71,488 KB
testcase_14 AC 78 ms
71,504 KB
testcase_15 AC 178 ms
79,480 KB
testcase_16 AC 160 ms
79,160 KB
testcase_17 AC 153 ms
78,996 KB
testcase_18 AC 166 ms
79,412 KB
testcase_19 AC 119 ms
78,432 KB
testcase_20 AC 149 ms
79,104 KB
testcase_21 AC 141 ms
78,664 KB
testcase_22 AC 172 ms
79,548 KB
testcase_23 AC 158 ms
78,836 KB
testcase_24 AC 173 ms
79,524 KB
testcase_25 AC 172 ms
79,608 KB
testcase_26 AC 747 ms
102,612 KB
testcase_27 AC 496 ms
93,508 KB
testcase_28 AC 578 ms
94,936 KB
testcase_29 AC 850 ms
107,208 KB
testcase_30 AC 472 ms
92,500 KB
testcase_31 AC 582 ms
96,636 KB
testcase_32 AC 802 ms
105,968 KB
testcase_33 AC 507 ms
93,480 KB
testcase_34 AC 600 ms
97,312 KB
testcase_35 AC 490 ms
119,988 KB
testcase_36 AC 1,092 ms
266,148 KB
testcase_37 AC 628 ms
107,676 KB
testcase_38 AC 78 ms
71,476 KB
testcase_39 AC 1,222 ms
253,588 KB
testcase_40 AC 1,238 ms
255,692 KB
testcase_41 AC 1,223 ms
252,892 KB
testcase_42 AC 1,212 ms
253,208 KB
testcase_43 AC 1,293 ms
256,960 KB
testcase_44 AC 1,255 ms
252,964 KB
testcase_45 AC 1,231 ms
256,344 KB
testcase_46 AC 1,235 ms
254,124 KB
testcase_47 AC 1,225 ms
252,380 KB
testcase_48 AC 1,221 ms
253,736 KB
testcase_49 AC 1,205 ms
394,452 KB
testcase_50 AC 788 ms
101,972 KB
testcase_51 AC 770 ms
101,976 KB
testcase_52 AC 774 ms
102,120 KB
testcase_53 AC 765 ms
102,164 KB
testcase_54 AC 786 ms
102,704 KB
testcase_55 AC 974 ms
264,816 KB
testcase_56 AC 859 ms
107,736 KB
testcase_57 AC 877 ms
107,240 KB
testcase_58 AC 853 ms
106,980 KB
testcase_59 AC 612 ms
127,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 9)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
from heapq import *

n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append(v)
    edges[v].append(u)

def dfs(pos, bpos):
    hq = []
    for npos in edges[pos]:
        if npos == bpos:
            continue
        else:
            tmp = dfs(npos, pos)
            if len(hq) > len(tmp):
                for t in tmp:
                    heappush(hq, t)
            else:
                for h in hq:
                    heappush(tmp, h)
                hq = tmp
    add = -1
    for _ in range(2):
        if hq:
            add += heappop(hq)
    heappush(hq, add)
    return hq

hq = dfs(0, -1)
print(-hq[0])
0