結果

問題 No.1928 Make a Binary Tree
ユーザー tnodinotnodino
提出日時 2022-05-06 22:48:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 773 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 131,732 KB
最終ジャッジ日時 2023-09-20 03:56:16
合計ジャッジ時間 16,992 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,476 KB
testcase_01 AC 77 ms
71,288 KB
testcase_02 AC 76 ms
71,472 KB
testcase_03 AC 78 ms
71,368 KB
testcase_04 AC 78 ms
71,408 KB
testcase_05 AC 77 ms
71,404 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 80 ms
71,412 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):
    x = Dist[i][1]
    pos = G2[x]
    Queue = []
    while pos != -1:
        Queue.append(pos)
        if Cnt[pos] < 2:
            Cnt[pos] += 1
            break
        pos = G2[pos]
    if pos == -1:
        for k in Queue:
            G2[k] = -1
        Flg[x] = 0
print(sum(Flg))
0