목차

Vertex Merge Game

ps
링크acmicpc.net/…
출처BOJ
문제 번호23736
문제명Vertex Merge Game
레벨플래티넘 2
분류

게임 이론

시간복잡도O(ElogE)
인풋사이즈E<=300,000
사용한 언어Python 3.11
제출기록89888KB / 820ms
최고기록820ms
해결날짜2023/07/15

풀이

코드

"""Solution code for "BOJ 23736. Vertex Merge Game".

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

Tags: [game theory]
"""

import sys
from teflib import graph as tgraph


def main():
    N, M = [int(x) for x in sys.stdin.readline().split()]
    edges = []
    for _ in range(M):
        u, v, w = [int(x) for x in sys.stdin.readline().split()]
        edges.append((u - 1, v - 1, -w))

    mst_edges = tgraph.minimum_spanning_tree(edges, N)
    woongbae = -sum(w for _, _, w in mst_edges)
    yunee = sum((i // 2) * ((i + 1) // 2) for i in range(N + 1))
    if yunee == woongbae:
        print('tie')
    else:
        print('win' if yunee > woongbae else 'lose')


if __name__ == '__main__':
    main()