| 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()