Algorithm/boj

[파이썬] 11375 열혈강호

takeU 2022. 10. 30. 15:48
반응형
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
graph = [list(map(int, input().split()))[1:] for _ in range(n)]
selected = [-1] * (m + 1)

def bimatch(num):
    if visited[num]:
        return False
    visited[num] = 1
    for g in graph[num]:
        if selected[g] == -1 or bimatch(selected[g]):
            selected[g] = num
            print(selected)
            return True
    return False

for i in range(n):
    visited = [0] * n
    bimatch(i)

print(m - selected.count(-1) + 1)​

이분매칭, dfs