Related concepts bipartite graph (a)

1, a bipartite graph:

Setting G = (V, E) be a graph, FIG set of vertices can be divided into two sets V1, V2, each side has a point E in either belong

Set points V1, the other belonging to point V2.

 

2, the maximum matching of bipartite graph:

(1) Match: an edge is a match, that is, two points matched by an edge, and a set of edges matched without being connected to any two sides.

(2) maximum matching: the set of edges contain up side can be included in a FIG.

Maximum Matching (3) bipartite graph: maximum matching bipartite graph can be included.

 

3, minimum vertex cover bipartite graph:

(1) Definition: The minimum vertex cover is bipartite graph (a point at which it can cover the side), the minimum vertex cover bipartite graph is

Select all the edges of a minimum vertex cover number.

Minimum vertex (2) covering the bipartite graph = maximum matching of bipartite graph.

 

Maximum independent set 4, a bipartite graph

(1) Definition: selecting some of the points from the bipartite graph, these points twenty-two adjacent to each other.

(2) = the number of maximum independent set of vertices bipartite graph - the minimum vertex cover bipartite graph.

EG ( FIG Pirates of ):

Minimum vertex cover the underlying bipartite graph is V1 = {1,2,4};

Therefore, maximum independent set bipartite graph V '= V - V1 = {3,5,6,7,8,9};

 

5, augmenting path:

(1) matching side: the other side have no side intersection

(2) alternate path: the path traversed is: non-matching edges -> Match side -> Mismatched side -> ...... -> Match side -> the non-matching edges;

Alternate path:

First, the beginning and end of some non-edge matching,

Second, the number of sides matching the number of non-matching edges = --1;

Third, the first point and last point of a certain non-matching point.

eg:

FIG alternative path of a red arrow is matched with the edge, matching the black side with black arrows

Red to match point, match point non-black

6

 (2) augmenting paths:

Not from a match point began to take alternate paths resulting augmenting path.

 

Nature (3) augmenting path

 

 

 

6, Hungarian algorithm
(1) Function: bipartite graph obtained by finding the maximum matching augmenting paths.

(2) basic process:

(3) Properties:

(4) code implementation:

bool dfs(int x){
	for(int i=head[x];i!=-1;i=cur[i].nxt){
		int y = cur[i].v;
		if(vis[y]==0){
			vis[y] = 1;
			if(pre[y]==-1||dfs(pre[y])){ 
            //pre数组相是记录路径,vis是记录是否被访问到
/*
这里的判断表示判断这点是否为未匹配点(pre[y]==-1),
如果不是未匹配点,假设选择这个点,
然后回溯修改之前的路径如果得到新的未匹配点说明得到了新的匹配路径(dfs(pre[y]))。
*/
				pre[y] = x;
				return true;
			}
		}
	}
	return false;
}
int fun(){
	int ans = 0;
	memset(pre,-1,sizeof(pre));
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		if(dfs(i)) ans++; 
        //从第i个节点开始判断是否能找到新的增广路径
	}
	return ans; 
    //求出的结果就是最大匹配数
}

 

Reference article:

(1) bipartite graph concepts

(2) Hungary algorithm

Guess you like

Origin blog.csdn.net/qq_41829060/article/details/92180709