목차

TV Show Game

ps
링크acmicpc.net/…
출처BOJ
문제 번호16367
문제명TV Show Game
레벨플래티넘 2
분류

2-sat

시간복잡도O(n+m)
인풋사이즈n<=5000, m<=10000
사용한 언어Python
제출기록38172KB / 168ms
최고기록116ms
해결날짜2022/11/03
태그

[단계]강한 연결 요소

풀이

코드

"""Solution code for "BOJ 16367. TV Show Game".

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

Tags: [2-Sat]
"""

import sys
from teflib import twosat


def main():
    k, n = [int(x) for x in sys.stdin.readline().split()]
    two_sat = twosat.TwoSat(k)
    for _ in range(n):
        l1, c1, l2, c2, l3, c3 = sys.stdin.readline().split()
        x1 = int(l1) - 1 if c1 == 'B' else -int(l1)
        x2 = int(l2) - 1 if c2 == 'B' else -int(l2)
        x3 = int(l3) - 1 if c3 == 'B' else -int(l3)
        two_sat.at_most_one((x1, x2, x3))

    try:
        assignment = two_sat.find_truth_assignment()
    except ValueError:
        print('-1')
    else:
        print(''.join('R' if x else 'B' for x in assignment))


if __name__ == '__main__':
    main()