結果

問題 No.1928 Make a Binary Tree
ユーザー tnodinotnodino
提出日時 2022-05-06 22:22:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 97,096 KB
最終ジャッジ日時 2023-09-20 03:20:04
合計ジャッジ時間 29,738 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,756 KB
testcase_01 AC 17 ms
7,780 KB
testcase_02 AC 16 ms
7,756 KB
testcase_03 AC 17 ms
7,756 KB
testcase_04 AC 17 ms
7,780 KB
testcase_05 AC 16 ms
7,868 KB
testcase_06 WA -
testcase_07 AC 18 ms
7,736 KB
testcase_08 AC 17 ms
7,740 KB
testcase_09 AC 16 ms
7,728 KB
testcase_10 AC 17 ms
7,856 KB
testcase_11 AC 16 ms
7,872 KB
testcase_12 AC 16 ms
7,708 KB
testcase_13 WA -
testcase_14 AC 17 ms
7,708 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 737 ms
42,528 KB
testcase_36 AC 808 ms
67,756 KB
testcase_37 AC 696 ms
32,144 KB
testcase_38 AC 16 ms
7,936 KB
testcase_39 AC 822 ms
61,576 KB
testcase_40 AC 823 ms
61,456 KB
testcase_41 AC 826 ms
61,576 KB
testcase_42 AC 827 ms
61,488 KB
testcase_43 AC 824 ms
61,608 KB
testcase_44 AC 814 ms
61,544 KB
testcase_45 AC 827 ms
61,456 KB
testcase_46 AC 835 ms
61,500 KB
testcase_47 AC 830 ms
61,436 KB
testcase_48 AC 829 ms
61,472 KB
testcase_49 AC 869 ms
88,604 KB
testcase_50 AC 798 ms
34,216 KB
testcase_51 AC 785 ms
34,424 KB
testcase_52 AC 782 ms
34,360 KB
testcase_53 AC 786 ms
34,428 KB
testcase_54 AC 779 ms
34,260 KB
testcase_55 AC 1,069 ms
97,096 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**6)

def dfs1(pos):
    ret = 1
    for nxt in G[pos]:
        ret += dfs1(nxt)
    Dist[pos] = ret
    return ret

def dfs2(cnt, pos):
    global ans
    if len(G[pos]) == 0:
        return
    if len(G[pos]) == 1:
        dfs2(cnt+1, G[pos][0])
        return
    D = 2 + cnt
    K = []
    for nxt in G[pos]:
        K.append((Dist[nxt], nxt))
    K.sort(reverse=True)
    N = K[:D]
    M = K[D:]
    for d,n in M:
        ans -= d
    cnt = max(0, cnt-(len(N)-2))
    for d,n in N:
        dfs2(cnt, n)
    return

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    G[x].append(y)
Dist = [-1] * N
dfs1(0)
ans = N
dfs2(0, 0)
print(ans)
0