匈牙利算法

 匈牙利算法就是匹配最大度的问题

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值