목차

아이돌

ps
링크acmicpc.net/…
출처BOJ
문제 번호3648
문제명아이돌
레벨플래티넘 3
분류

2-sat

시간복잡도O(T*(n+m))
인풋사이즈T<=?, n<=1000, m<=2000
사용한 언어Python
제출기록32688KB / 444ms
최고기록276ms
해결날짜2022/11/03
태그

[단계]강한 연결 요소 [라이]2-SAT 문제

풀이

코드

"""Solution code for "BOJ 3648. 아이돌".

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

Tags: [2-sat]
"""

import sys
from teflib import twosat


def main():
    while line := sys.stdin.readline():
        n, m = [int(x) for x in line.split()]
        two_sat = twosat.TwoSat(n)
        for _ in range(m):
            a, b = [int(x) for x in sys.stdin.readline().split()]
            x = a - 1 if a > 0 else a
            y = b - 1 if b > 0 else b
            two_sat.x_or_y(x, y)
        two_sat.x_is_true(0)

        print('yes' if two_sat.is_satisfiable() else 'no')


if __name__ == '__main__':
    main()