사용자 도구

사이트 도구


ps:problems:boj:11280

2-SAT - 3

ps
링크acmicpc.net/…
출처BOJ
문제 번호11280
문제명2-SAT - 3
레벨플래티넘 4
분류

2-sat

시간복잡도O(n+m)
인풋사이즈n<=10,000, m<=100,000
사용한 언어Python
제출기록52692KB / 332ms
최고기록224ms
해결날짜2022/10/28
태그

[라이]2-SAT 문제

풀이

  • 2-SAT에서 해가 존재여부를 확인하는 기본 문제. 2-sat 알고리즘을 그대로 구현해서 돌리면 된다. 시간복잡도는 O(n+m)

코드

"""Solution code for "BOJ 11280. 2-SAT - 3".

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

Tags: [2-sat]
"""

import sys
from teflib import twosat


def main():
    N, M = [int(x) for x in sys.stdin.readline().split()]
    two_sat = twosat.TwoSat(N)
    for _ in range(M):
        i, j = [int(x) for x in sys.stdin.readline().split()]
        x = i - 1 if i > 0 else i
        y = j - 1 if j > 0 else j
        two_sat.x_or_y(x, y)

    print('1' if two_sat.is_satisfiable() else '0')


if __name__ == '__main__':
    main()

토론

댓글을 입력하세요:
R K T J​ E
 
ps/problems/boj/11280.txt · 마지막으로 수정됨: 2022/11/07 16:25 저자 teferi