結果

問題 No.1928 Make a Binary Tree
ユーザー mkawa2mkawa2
提出日時 2022-05-08 09:57:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,375 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 96,264 KB
最終ジャッジ日時 2023-09-22 03:51:22
合計ジャッジ時間 35,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,260 KB
testcase_01 AC 18 ms
8,192 KB
testcase_02 AC 18 ms
8,256 KB
testcase_03 AC 19 ms
8,256 KB
testcase_04 AC 18 ms
8,144 KB
testcase_05 AC 18 ms
8,144 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 18 ms
8,216 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
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 688 ms
62,752 KB
testcase_36 AC 790 ms
78,324 KB
testcase_37 WA -
testcase_38 AC 18 ms
8,136 KB
testcase_39 AC 946 ms
77,968 KB
testcase_40 AC 931 ms
78,040 KB
testcase_41 AC 924 ms
77,880 KB
testcase_42 AC 951 ms
78,144 KB
testcase_43 AC 933 ms
78,032 KB
testcase_44 AC 943 ms
77,940 KB
testcase_45 AC 952 ms
78,184 KB
testcase_46 AC 925 ms
78,000 KB
testcase_47 AC 921 ms
77,972 KB
testcase_48 AC 935 ms
77,956 KB
testcase_49 AC 772 ms
96,264 KB
testcase_50 AC 1,026 ms
57,164 KB
testcase_51 AC 1,028 ms
57,152 KB
testcase_52 AC 1,027 ms
57,024 KB
testcase_53 AC 1,043 ms
57,196 KB
testcase_54 AC 1,038 ms
57,040 KB
testcase_55 AC 735 ms
79,744 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 836 ms
53,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

from heapq import *

n = II()
to = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = LI1()
    to[u].append(v)
    to[v].append(u)

size = [1]*n
hps = [[] for _ in range(n)]

def merge(u, v):
    swap = False
    if len(hps[u]) < len(hps[v]):
        u, v = v, u
        swap = True
    for s in hps[v]: heappush(hps[u], s)
    if swap: hps[v] = hps[u]

def dfs(u=0, par=-1):
    # ss = []
    for v in to[u]:
        if v == par: continue
        dfs(v, u)
        merge(u, v)
        hps[u].append(-size[v])
    if hps[u]: size[u] -= heappop(hps[u])
    if hps[u]: size[u] -= heappop(hps[u])
    # print(u, par, size, hps)

dfs()

print(size[0])
0