結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー maspymaspy
提出日時 2020-05-05 22:38:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,026 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 11,108 KB
実行使用メモリ 48,960 KB
最終ジャッジ日時 2023-09-09 13:19:51
合計ジャッジ時間 11,485 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,248 KB
testcase_01 AC 18 ms
8,184 KB
testcase_02 WA -
testcase_03 AC 18 ms
8,272 KB
testcase_04 AC 19 ms
8,612 KB
testcase_05 AC 19 ms
8,348 KB
testcase_06 AC 18 ms
8,196 KB
testcase_07 AC 340 ms
27,856 KB
testcase_08 AC 148 ms
18,548 KB
testcase_09 AC 195 ms
20,444 KB
testcase_10 AC 143 ms
17,556 KB
testcase_11 AC 580 ms
38,804 KB
testcase_12 AC 577 ms
39,052 KB
testcase_13 AC 562 ms
38,028 KB
testcase_14 AC 562 ms
38,012 KB
testcase_15 AC 605 ms
39,784 KB
testcase_16 AC 620 ms
40,048 KB
testcase_17 AC 620 ms
40,696 KB
testcase_18 AC 565 ms
48,692 KB
testcase_19 AC 592 ms
48,960 KB
testcase_20 AC 588 ms
48,184 KB
testcase_21 AC 550 ms
45,660 KB
20evil_special_uni1.txt AC 601 ms
42,760 KB
20evil_special_uni2.txt AC 584 ms
40,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int, read().split())

G = [[] for _ in range(N + 1)]
for a, b in zip(m, m):
    G[a].append(b)
    G[b].append(a)

root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in G[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

dp_v = [[0, 0] for _ in range(N + 1)]
dp_e_d = [False] * (N + 1)

for v in order[::-1]:
    p = parent[v]
    if dp_v[v][0] == 0:
        dp_e_d[v] = True
        dp_v[p][0] += 1
    else:
        dp_v[p][1] += 1

dp_e_u = [False] * (N + 1)
for v in order:
    if v == root:
        continue
    p = parent[v]
    dp_e_u[v] = dp_v[p][0] - (dp_e_d[v]) == 0
    if dp_e_u[v]:
        dp_v[v][0] += 1
    else:
        dp_v[v][1] += 1

win_v = [v for v in range(1, N + 1) if not dp_v[v][0]]

print(len(win_v))
print('\n'.join(map(str, win_v)))
0