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()