ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 3747 |
문제명 | 완벽한 선거! |
레벨 | 플래티넘 4 |
분류 |
2-sat |
시간복잡도 | O(T*(N+M)) |
인풋사이즈 | T<=?, N<=1000, M<=1,000,000 |
사용한 언어 | Python |
제출기록 | 494408KB / 4308ms |
최고기록 | 3748ms |
해결날짜 | 2022/11/07 |
태그 |
"""Solution code for "BOJ 3747. 완벽한 선거!".
- Problem link: https://www.acmicpc.net/problem/3747
- Solution link: http://www.teferi.net/ps/problems/boj/3747
Tags: [2-sat]
"""
import sys
from teflib import twosat
def main():
inp = iter(sys.stdin.read().split())
while True:
try:
N = int(next(inp))
except StopIteration:
break
two_sat = twosat.TwoSat(N)
M = int(next(inp))
for _ in range(M):
x, y = (int(next(inp)), int(next(inp)))
x = x - 1 if x > 0 else x
y = y - 1 if y > 0 else y
two_sat.x_or_y(x, y)
print('1' if two_sat.is_satisfiable() else '0')
if __name__ == '__main__':
main()