結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー H3PO4H3PO4
提出日時 2021-02-01 10:57:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 882 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 52,452 KB
最終ジャッジ日時 2023-09-12 10:07:15
合計ジャッジ時間 12,639 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,648 KB
testcase_01 AC 19 ms
8,548 KB
testcase_02 AC 20 ms
8,552 KB
testcase_03 WA -
testcase_04 AC 24 ms
8,964 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 405 ms
31,668 KB
testcase_08 AC 210 ms
20,056 KB
testcase_09 WA -
testcase_10 AC 188 ms
19,080 KB
testcase_11 AC 641 ms
43,528 KB
testcase_12 AC 653 ms
43,776 KB
testcase_13 AC 616 ms
42,680 KB
testcase_14 AC 623 ms
42,688 KB
testcase_15 AC 664 ms
44,904 KB
testcase_16 AC 678 ms
44,876 KB
testcase_17 AC 690 ms
45,588 KB
testcase_18 AC 660 ms
52,004 KB
testcase_19 AC 672 ms
52,452 KB
testcase_20 AC 675 ms
50,376 KB
testcase_21 AC 628 ms
48,572 KB
20evil_special_uni1.txt AC 676 ms
46,648 KB
20evil_special_uni2.txt AC 639 ms
44,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
T = [[] for _ in range(N)]
AB = [tuple(int(x) - 1 for x in input().split()) for _ in range(N - 1)]
for a, b in AB:
    T[a].append(b)
    T[b].append(a)

# dfs
dfs_order = []
d = deque([0])
nonvisited = [True] * N
nonvisited[0] = False
while d:
    v = d.pop()
    for x in T[v]:
        if nonvisited[x]:
            d.append(x)
            dfs_order.append((x, v))
            nonvisited[x] = False

# 子から親へ
dp0, dp1 = [0] * N, [0] * N
for child, v in reversed(dfs_order):
    if dp0[child] == len(T[child]) - 1:
        dp1[v] += 1
    else:
        dp0[v] += 1

# 親から子へ
win = set()
if not dp1[0]:
    win.add(0)
for child, v in dfs_order:
    if v in win:
        dp1[child] += 1
    if not dp1[child] and dp1[v] != 1:
        win.add(child)

print(len(win))
if win:
    print(*(w + 1 for w in win), sep='\n')
0