목차

복수전공

ps
링크acmicpc.net/…
출처BOJ
문제 번호12843
문제명복수전공
레벨플래티넘 3
분류

이분 매칭, 최대 독립집합

시간복잡도O(VE)
인풋사이즈V<=2000, E<=2,000,000
사용한 언어Python
제출기록60052KB / 1052ms
최고기록1052ms
해결날짜2022/03/16

풀이

코드

"""Solution code for "BOJ 12843. 복수전공".

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

Tags: [Bipartite Matching]
"""

import sys
from teflib import tgraph


def main():
    # pylint: disable=unused-variable
    n, m = [int(x) for x in sys.stdin.readline().split()]
    bigraph = [[] for _ in range(n)]
    comp_lectures = set()
    for _ in range(n):
        lecture, dep = sys.stdin.readline().split()
        if dep == 'c':
            comp_lectures.add(int(lecture))
    for _ in range(m):
        lecture1, lecture2 = [int(x) for x in sys.stdin.readline().split()]
        if lecture1 in comp_lectures:
            bigraph[lecture1 - 1].append(lecture2 - 1)
        else:
            bigraph[lecture2 - 1].append(lecture1 - 1)

    print(n - len(tgraph.bipartite_matching(bigraph)))


if __name__ == '__main__':
    main()