목차

게임이론

ps
링크acmicpc.net/…
출처BOJ
문제 번호16142
문제명게임이론
레벨플래티넘 1
분류

게임 이론

시간복잡도O(n+m)
인풋사이즈n<=50,000, m<=500,000
사용한 언어Python 3.11
제출기록81580KB / 808ms
최고기록808ms
해결날짜2023/07/12

풀이

코드

"""Solution code for "BOJ 16142. 게임이론".

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

Tags: [game theory]
"""

import sys
from teflib import graph as tgraph

INF = float('inf')


def main():
    n, m, s = [int(x) for x in sys.stdin.readline().split()]
    w = [int(x) for x in sys.stdin.readline().split()]
    graph = tgraph.create_graph_from_input(n, m)
    source = s - 1

    dist = [-1 if w_i > 1 else INF for w_i in w]
    one_count = sum(1 for u in tgraph.bfs(graph, source, distances=dist))
    if one_count == n:
        is_win_pos = n % 2 == 1
    else:
        is_win_pos = one_count % 2 == 0

    print('hwy' if is_win_pos else 'sjh')


if __name__ == '__main__':
    main()