Bipartite graph conclusion + board

in conclusion:

The construction of a map is generally divided into two parts to build a bipartite map, and various errors will occur when the parts are mixed.

①The minimum number of points covered = the maximum number of matches

②Maximum independent set + minimum vertex cover (maximum matching) = number of vertices in a bipartite graph

③ Minimum edge coverage = maximum independent set = n - maximum number of matches

Proof: Let the maximum number of matches be m and the total number of vertices be n. In order to minimize the number of edges, and because one edge can kill up to two points, try to use the edge to kill two points. That is to take those edges with matching, of course, the more these edges, the better, that is the maximum matching, so first use the edges with the maximum matching number to kill most points. The remaining points that are not matched can only be eliminated by one edge. Let these numbers be a. Obviously, 2m+a=n, and the minimum edge coverage = m+a, so the minimum edge coverage = (2m +a)-m=nm.

④ Minimum path coverage, the given graph is not required to be a bipartite graph, but a directed graph acyclic graph of PXP , and then a bipartite graph is constructed according to the original graph. The construction method is to divide the points into two, for example, i is divided into i1 and i2 Then if i and j have an edge, then connect an edge between i1 and j2. This constitutes a bipartite graph, in fact, the original n points are divided into n boys and n girls.

Then the minimum path coverage is nm, where n is the number of points in the original graph, and m is the maximum matching of the newly created bipartite graph.

 

⑤ Solution steps for edge coverage of undirected graph G(V, E):

1. Split the undirected graph, that is, if there is a node i in the undirected graph, then split the node i into i1, i2 are located in the X part and the Y part of the bipartite graph. If there is an edge ij, then connect the bipartite graph. i1j2,i2j1.

2. The number of nodes in the original undirected graph is |V|, so there are 2*|V| nodes in the constructed bipartite graph. In a bipartite graph there is a formula:

2*|V| = 2*Maximum number of matches in the bipartite graph + unmatched points in the bipartite graph. The maximum number of matches in the bipartite graph + the unmatched points in the bipartite graph cover all the points in the bipartite graph. Compared with the original undirected graph, it is equivalent to covering each point twice, that is, the minimum value of the original edge coverage. is the maximum number of matches in the bipartite graph + the minimum number of unmatched points in the bipartite graph. There is also the formula 2*|V| = 2* the maximum number of matches in the bipartite graph + the unmatched points in the bipartite graph, we can get:

The maximum number of matches in the bipartite graph + the unmatched points in the bipartite graph = 2*|V| - the maximum number of matches in the bipartite graph, and this result covers all the vertices of the original graph twice, so the result should be divided by 2.

So the minimum edge coverage of an undirected graph = |V| - the maximum number of matches for a bipartite graph/2.

Hungarian algorithm explanation: click to open the link

board:

#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const double esp = 1e-7;
const int ff = 0x3f3f3f3f;
map<int,int>::iterator it;

int n,m,k;
int mp[520][520];
int vis[520];
int g[520];

int find(int x)
{
	for(int i = 1;i<= n;i++)
	{
		if(mp[x][i]&&!vis[i])
		{
			show [i] = 1;
			if(!g[i]||find(g[i]))
			{
				g[i] = x;
				return 1;
			}
		}
	}
	return 0;
}

void init()
{
	mem(mp,0);
	mem(g,0);
}

intmain()
{
	int t;
	cin>>t;
	while(t--)
	{
		init();
		scanf("%d %d",&m,&n);
		for(int i = 1;i<= m;i++)
		{
			int a,b;
			scanf("%d %d",&a,&b);
			mp [a] [b] = 1;
		}
		
		int years = 0;
		for(int i = 1;i<= m;i++)
		{
			mem(vis,0);
			if(find(i))
				years++;
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325903034&siteId=291194637