結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー ninja-kidninja-kid
提出日時 2023-02-24 01:59:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,596 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 33,464 KB
最終ジャッジ日時 2023-10-01 00:48:25
合計ジャッジ時間 11,617 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,832 KB
testcase_01 AC 20 ms
8,856 KB
testcase_02 WA -
testcase_03 AC 24 ms
8,936 KB
testcase_04 AC 23 ms
8,856 KB
testcase_05 AC 24 ms
8,940 KB
testcase_06 AC 23 ms
8,864 KB
testcase_07 AC 416 ms
20,976 KB
testcase_08 AC 207 ms
15,148 KB
testcase_09 AC 251 ms
16,388 KB
testcase_10 AC 192 ms
14,492 KB
testcase_11 AC 652 ms
27,732 KB
testcase_12 AC 663 ms
27,820 KB
testcase_13 AC 640 ms
27,276 KB
testcase_14 AC 633 ms
27,368 KB
testcase_15 AC 675 ms
28,480 KB
testcase_16 AC 679 ms
28,536 KB
testcase_17 AC 696 ms
28,916 KB
testcase_18 AC 619 ms
32,844 KB
testcase_19 AC 634 ms
33,464 KB
testcase_20 AC 639 ms
32,668 KB
testcase_21 AC 612 ms
31,216 KB
20evil_special_uni1.txt AC 664 ms
30,112 KB
20evil_special_uni2.txt AC 637 ms
29,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
from bisect import bisect_left, bisect_right
from collections import deque
from itertools import permutations
from sys import setrecursionlimit


dpos4 = ((1, 0), (0, 1), (-1, 0), (0, -1))
dpos8 = ((0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1))
mod1 = 10**9 + 7
mod2 = 998244353
inf = 1 << 60


def main():
    N = int(input())
    edges = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        edges[u].append(v)
        edges[v].append(u)

    dp1 = [True] * N
    dp2 = [True] * N

    setrecursionlimit(10**6)

    def dfs1(fr, prev=-1):
        val = False
        for to in edges[fr]:
            if to == prev:
                continue
            dfs1(to, fr)
            val |= dp1[to]
        dp1[fr] = not val

    def dfs2(fr, prev=-1):
        val = False
        for to in edges[fr]:
            val |= dp1[to]
        dp2[fr] = not val
        L = len(edges[fr])
        lval = [False] * (L + 1)
        rval = [False] * (L + 1)
        for i in range(L):
            to = edges[fr][i]
            lval[i + 1] = lval[i] or dp1[to]
            j = L - 1 - i
            to = edges[fr][j]
            rval[j] = rval[j + 1] or dp1[to]
        for i in range(L):
            to = edges[fr][i]
            if to == prev:
                continue
            dp1[fr] = not (lval[i] or rval[i + 1])
            dfs2(to, fr)


    dfs1(0)
    dfs2(0)
    print(sum(dp2))
    print(*(i + 1 for i in range(N) if dp2[i]), sep='\n')


if __name__ == "__main__":
    main()
0