結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー maspymaspy
提出日時 2020-05-05 22:40:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 48,772 KB
最終ジャッジ日時 2023-09-09 13:23:46
合計ジャッジ時間 8,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,240 KB
testcase_01 AC 15 ms
8,272 KB
testcase_02 AC 15 ms
8,244 KB
testcase_03 AC 17 ms
8,176 KB
testcase_04 AC 18 ms
8,568 KB
testcase_05 AC 17 ms
8,284 KB
testcase_06 AC 16 ms
8,328 KB
testcase_07 AC 242 ms
27,876 KB
testcase_08 AC 118 ms
18,316 KB
testcase_09 AC 138 ms
20,456 KB
testcase_10 AC 110 ms
17,548 KB
testcase_11 AC 395 ms
38,876 KB
testcase_12 AC 410 ms
39,168 KB
testcase_13 AC 386 ms
38,028 KB
testcase_14 AC 387 ms
38,016 KB
testcase_15 AC 429 ms
40,316 KB
testcase_16 AC 431 ms
40,036 KB
testcase_17 AC 457 ms
40,560 KB
testcase_18 AC 429 ms
48,772 KB
testcase_19 AC 433 ms
48,704 KB
testcase_20 AC 438 ms
47,668 KB
testcase_21 AC 401 ms
45,668 KB
20evil_special_uni1.txt AC 423 ms
42,624 KB
20evil_special_uni2.txt AC 404 ms
40,964 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))
if win_v:
    print('\n'.join(map(str, win_v)))
0