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