匈牙利算法就是匹配最大度的问题
max_node =100
bigraph=[[ False for i in range(max_node)]for j in range(max_node)]
parent=[False for i in range(max_node)]
visited =[ False for j in range(max_node)]
result={}
max_matching = 0
x_node = int(input("please input the num of x_node: "))
y_node = int(input("please input the num of y_node: "))
edge_num = int(input("please input the num of edge: "))
for i in range(edge_num):
start_node , end_node =map(lambda x:int(x),input(" enter the start_node and end_node(split by space): ").split(" "))
bigraph[start_node][end_node]=True
def find_argumenting_path(start_node):
for next_node in range(1,1+y_node):
if not visited[next_node] and bigraph[start_node][next_node]:
visited[next_node]=True
if not parent[next_node] or find_argumenting_path(next_node):
parent[next_node]=start_node
result[start_node]=[next_node]
return True
return False
for node in range(1,1+x_node):
visited = [False for j in range(max_node)]
if find_argumenting_path(node):
max_matching+=1
print(max_matching)
print(result)