結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,772 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 AC 17 ms
7,924 KB
testcase_03 AC 16 ms
7,776 KB
testcase_04 AC 16 ms
7,724 KB
testcase_05 AC 16 ms
7,744 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 16 ms
7,728 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 WA -
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 #

from sys import setrecursionlimit
setrecursionlimit(10**6)

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

N = int(input())
G1 = [[] for _ in range(N)]
G2 = [-1] * N
for _ in range(N-1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    G1[x].append(y)
    G2[y] = x
Dist = [-1] * N
dfs1(0)
for i in range(N):
    Dist[i] = [Dist[i], i]
Dist.sort(reverse=True)
Cnt = [0] * N
Flg = [1] * N
for i in range(1,N):
    pos = G2[i]
    Queue = [pos]
    while pos != -1:
        if Cnt[pos] < 2:
            Cnt[pos] += 1
            break
        pos = G2[pos]
        Queue.append(pos)
    if pos == -1:
        for k in Queue:
            G2[k] = -1
        Flg[i] = 0
print(sum(Flg))
0