結果

問題 No.1928 Make a Binary Tree
ユーザー mkawa2mkawa2
提出日時 2022-05-06 21:51:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,180 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 99,616 KB
最終ジャッジ日時 2023-09-20 02:43:48
合計ジャッジ時間 27,310 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,260 KB
testcase_01 AC 16 ms
8,388 KB
testcase_02 AC 16 ms
8,388 KB
testcase_03 AC 16 ms
8,368 KB
testcase_04 AC 16 ms
8,272 KB
testcase_05 AC 16 ms
8,384 KB
testcase_06 WA -
testcase_07 AC 17 ms
8,212 KB
testcase_08 AC 16 ms
8,212 KB
testcase_09 AC 16 ms
8,312 KB
testcase_10 AC 16 ms
8,280 KB
testcase_11 AC 16 ms
8,204 KB
testcase_12 AC 17 ms
8,260 KB
testcase_13 WA -
testcase_14 AC 17 ms
8,236 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 630 ms
48,884 KB
testcase_36 AC 643 ms
73,416 KB
testcase_37 AC 552 ms
42,820 KB
testcase_38 AC 16 ms
8,368 KB
testcase_39 AC 800 ms
71,552 KB
testcase_40 AC 800 ms
71,424 KB
testcase_41 AC 820 ms
71,476 KB
testcase_42 AC 822 ms
71,424 KB
testcase_43 AC 808 ms
71,404 KB
testcase_44 AC 827 ms
71,528 KB
testcase_45 AC 788 ms
71,364 KB
testcase_46 AC 810 ms
71,536 KB
testcase_47 AC 809 ms
71,416 KB
testcase_48 AC 802 ms
71,552 KB
testcase_49 AC 717 ms
99,616 KB
testcase_50 AC 834 ms
43,004 KB
testcase_51 AC 842 ms
42,864 KB
testcase_52 AC 831 ms
43,008 KB
testcase_53 AC 833 ms
42,968 KB
testcase_54 AC 838 ms
42,988 KB
testcase_55 AC 662 ms
74,452 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 674 ms
41,092 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

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

def dfs(u=0, par=-1):
    res = 0
    ss = []
    for v in to[u]:
        if v == par: continue
        res += dfs(v, u)
        ss.append(size[v])
    ss.sort(reverse=True)
    size[u] += sum(ss[:2])
    res += sum(ss[2:])
    if len(ss) < 2 and res:
        res -= 1
        size[u] += 1
    return res

dfs()

print(size[0])
0