Maximum Cardinality Bipartite Matching: Augmenting Path Algorithm

http://www.csie.ntnu.edu.tw/~u91029/Matching.html

 1 int nx,ny;
 2 int mx[N],my[N];
 3 bool vy[N];
 4 bool g[N][N];
 5
 6 int decode(int x,int y)   {return x*15+y;}
 7
 8 bool dfs(int x)
 9 {
10     for(int y=0;y<ny;++y)
11         if(g[x][y] && !vy[y])
12         {
13             vy[y]=1;
14             if(my[y]==-1 || dfs(my[y]))
15             {
16                 mx[x]=y;
17                 my[y]=x;
18                 return 1;
19             }
20         }
21     return 0;
22 }
23
24 int b_matching()
25 {
26     memset(mx,-1,sizeof(mx));
27     memset(my,-1,sizeof(my));
28     int c=0;
29     for(int x=0;x<nx;++x)
30     {
31         memset(vy,0,sizeof(vy));
32         if(dfs(x))  ++c;
33     }
34     return c;
35 }

Maximum Cardinality Bipartite Matching: Augmenting Path Algorithm

时间: 2024-10-13 08:00:16

Maximum Cardinality Bipartite Matching: Augmenting Path Algorithm的相关文章

Maximum Bipartite Matching

算法旨在用尽可能简单的思路解决问题,理解算法也应该是一个越看越简单的过程,当你看到算法里的一串概念,或者一大坨代码,第一感觉是复杂,此时不妨从例子入手,通过一个简单的例子,并编程实现,这个过程其实就可以理解清楚算法里的最重要的思想,之后扩展,对算法的引理或者更复杂的情况,对算法进行改进.最后,再考虑时间和空间复杂度的问题. 了解这个算法是源于在Network Alignment问题中,图论算法用得比较多,而对于alignment,特别是pairwise alignment, 又经常遇到maxim

Dijkstra’s Shortest Path Algorithm / LeetCode 787. Cheapest Flights Within K Stops

Dijkstra’s Shortest Path Algorithm 实现详见:https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-using-priority_queue-stl/ 需要注意的是,priority_queue并无法更新内部的元素,因此我们更新dist的同时,直接把新的距离加入pq即可.pq里虽然有outdated的dist,但是由于距离过长,他们并不会更新dist. // If there is sho

Stable Matching (Gale Sharpley Algorithm)

以下为数据生成函数,生成boys_rankings.txt 和 girls_rankings.txt #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <sstream> #include <algorithm> #include <vector> #inc

XShell 无法匹配的outgoing encryption算法 ,No matching outgoing encryption algorithm found

在链接的属性(SSH -> 安全性) 的加密算法列表中选择 aes256-ctr, mac加密列表中选择hmac-sha2-256,保存即可 To enable hmac-sha2-256 and aes256-ctr go to the SSH > Security page in the session properties. Click the Edit button for Encryption and MAC. Make sure everything is selected for

UVA - 753 A Plug for UNIX

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description You are in charge of setting up the press room for the inaugural meeting of the United Nations Internet eXecutive (UNIX), which has an international m

二分图最大匹配 -- 匈牙利算法

Algorithm.( Augmenting Path Algorithm ) Input: An X-Y bigraph G, a matching M in G, and the set U of M-unsaturated vertices in X. Idea: Explore M-alternating paths form U, letting S ? X and T ? Y be the sets of vertices reached. Marks vertices of S t

干货 | 自适应大邻域搜索(Adaptive Large Neighborhood Search)入

01 首先来区分几个概念 关于neighborhood serach,这里有好多种衍生和变种出来的胡里花俏的算法.大家在上网搜索的过程中可能看到什么Large Neighborhood Serach,也可能看到Very Large Scale Neighborhood Search或者今天介绍的Adaptive Large Neighborhood Search. 对于这种名字相近,实则大有不同的概念,很是让小编这样的新手头疼.不过,小编喜欢凡事都要弄得清清楚楚明明白白的.为了防止大家混淆这些相

Method for finding shortest path to destination in traffic network using Dijkstra algorithm or Floyd-warshall algorithm

A method is presented for finding a shortest path from a starting place to a destination place in a traffic network including one or more turn restrictions, one or more U-turns and one or more P-turns using a Dijkstra algorithm. The method as sets a

Codeforces534B:Covered Path

The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t seconds to