목차

A Tree Game

ps
링크acmicpc.net/…
출처BOJ
문제 번호33416
문제명A Tree Game
레벨골드 3
분류

게임 이론

시간복잡도O(n)
인풋사이즈n<=10^5
사용한 언어Python 3.13
제출기록52168KB / 208ms
최고기록208ms
해결날짜2025/10/04

풀이

코드

"""Solution code for "BOJ 33416. A Tree Game".

- Problem link: https://www.acmicpc.net/problem/33416
- Solution link: http://www.teferi.net/ps/problems/boj/33416

Tags: [game theory]
"""

from teflib import tree as ttree

ROOT = 0


def main():
    n, tree = ttree.create_tree_from_input()

    if n == 1:
        print('0')
        return
    if len(tree[ROOT]) == 1:
        print('1')
        return

    dp = ttree.dp_on_tree(
        tree,
        ROOT,
        lambda dp_ch, _: len(dp_ch) == 0 or dp_ch.count(True) >= 2,
    )
    print('1' if dp[ROOT] else '0')


if __name__ == '__main__':
    main()