# 参考 URL # https://snuke.hatenablog.com/entry/2019/05/07/013609 class Bipartite_Matching: def __init__(self,M,N): """ サイズが M,N からなる二部空グラフを作成する. """ self.M=M; self.N=N self.edge=[[] for _ in range(M)] def add_edge(self, a, b): """ 辺 Aa Bb を加える. """ assert 0<=a=1: G.add_edge(i,j) _,(P,_)=G.max_matching(True) for i in range(N): A[i][P[i]]-=1 print(*[P[i]+1 for i in range(N)]) return #================================================== solve()