ps:problems:boj:11281
                2-SAT - 4
| ps | |
|---|---|
| 링크 | acmicpc.net/… | 
| 출처 | BOJ | 
| 문제 번호 | 11281 | 
| 문제명 | 2-SAT - 4 | 
| 레벨 | 플래티넘 3 | 
| 분류 | 
 2-sat  | 
	
| 시간복잡도 | O(n+m) | 
| 인풋사이즈 | n<=10,000, m<=100,000 | 
| 사용한 언어 | Python | 
| 제출기록 | 52596KB / 336ms | 
| 최고기록 | 224ms | 
| 해결날짜 | 2022/10/28 | 
| 태그 | |
풀이
코드
"""Solution code for "BOJ 11281. 2-SAT - 4".
- Problem link: https://www.acmicpc.net/problem/11281
- Solution link: http://www.teferi.net/ps/problems/boj/11281
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)
    try:
        assignment = two_sat.find_truth_assignment()
    except ValueError:
        print('0')
    else:
        print('1')
        print(' '.join('1' if x else '0' for x in assignment))
if __name__ == '__main__':
    main()
- Dependency: teflib.twosat.TwoSat
 
ps/problems/boj/11281.txt · 마지막으로 수정됨: 2022/11/07 16:25 저자 teferi
                
                
토론