====== 2-SAT - 4 ====== ===== 풀이 ===== * [[ps:problems:boj:11280]] 에서, 해의 존재 여부뿐 아니라, 해를 하나 찾아서 출력하는 것이 추가된 문제. 여전히 [[ps:2-sat]]의 기본적인 형태이다. 시간복잡도는 O(n+m) ===== 코드 ===== """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: [[:ps:teflib:twosat#TwoSat|teflib.twosat.TwoSat]] {{tag>BOJ ps:problems:boj:플래티넘_3}}