Two-part graph matching
given a two-part graph G ( no map ) , in G a sub-diagram of M in which M any two edges in the edge set are not attached to the same vertex, it is said M is a match .
Choosing The largest subset of such edges is called the maximum matching problem for graphs (maximal matchingproblem)
If one match, each vertex in the diagram is associated with an edge in the graph, it is said to be an exact match, also known as a complete match.
if each edge of the binary graph has a weighted value and there is a complete match, then we need to find out that the problem of all edge weights and maximal complete matching is called the optimal matching problem of the binary graph.
(the template code for finding the maximum matching and optimal matching of binary graphs is given below)
Minimum cover number of a binary graph : Select the minimum number of point sets in the binary graph, so that there is at least one endpoint in the binary graph on either side of this point set. The size of this point set is the minimum coverage number of the binary graph, and the minimum coverage number of the binary graph = = the maximum match number of the binary graph.
the maximum independent set of two graphs ==| G| ( The maximum number of matches in a binary graph.
Minimum path overrides for Dags : Find as few paths as possible in the Dag graph, so that each node is on exactly one path ( There can be no common points for different paths ). Note: A separate node can also be used as a path.
DAGthe minimum path overlay solution is as follows: all nodesISplit to the left point setIand the right point set.i ', ifDAGthe picture hasIto theJhas a forward edge, then add a two-partIto theJ 'without a forward edge. UltimatelyDAGthe minimum path overlay number==dagnumber of nodes in the graphN-maximum matching number of new binary graphsm. Note: The originalDAGmaximum matching number of new binary graphs constructed by graphsm<=n-1 (Think about why)
(Detailed analysis visible Rujia << Training guide >>p357) Here I add something: for example, the DAG graph has a minimum path overlay of 1, then there are 1 paths in the Dag that contain exactly n points, Then there is a n-1 side match in the corresponding binary graph. Because only the end of the path in the DAG's path is unmatched, all other nodes have matching edges in the binary graph.
So if the minimum path of the DAG is overwritten with X, then there are X points that cannot be matched. Then the matching number of the two graphs is n-x. Summary: Number of DAG nodes N-binary graph matching number m==dag minimum path cover number
Is there a forward ring overlay for the graph? put all the nodes of the graphISplit to the left point setIand the right point set.i 'If there is a map in theIto theJhas a forward edge, then add a two-partIto theJ 'without a forward edge. Finally, if the maximum number of matches for the new binary graphm==number of nodes with a graphN, then all nodes of the graph can be precisely1one or more disjoint(No public node)covered with a forward ring.
The principle is similar to the interpretation of the minimum path overlay of a DAG , because each node can find a successor node to continue to go down, so there is bound to be a graph existence loop. And because there is only one successor for each node in a feasible maximum match, there is bound to be a disjoint ring overlay.
found in the map to Span style= "COLOR: #333333" >1 i Split to the left point set i i " i to Span style= "COLOR: #333333" >j i to j '
Here is the template for finding the maximum match of the binary graph
Binary graph maximum matching template, two-dimensional graph is a non-oriented graph//call the following algorithm before, to ensure that this diagram is a binary diagram/*************vecotr template *****************/#include <cstdio> #include <cstring> #include <vector>using namespace std;const int maxn=100+5;struct max_match{int n,m;//left and right point set size, Point starting from 1 vector<int> G[maxn];//g[i] represents the right-hand side of the first-point adjacency of the left of the set bool Vis[maxn];//vis[i] Indicates whether the right-side I-point is accessed in this match in the Int left [Maxn];//left[i]==j table to the right of point I points to the left of the J Point match, for 1 table no point match void init (int n,int m) {this->n=n; this->m=m; for (int i=1;i<=n;i++) g[i].clear (); memset (Left,-1,sizeof (left)); }//Determine if an augmented path bool match (int u) {for (int i=0;i<g[u].size (); i++) {int v=g[u] can be found from the left U point [i]; if (!vis[v]) {vis[v]=true; if (Left[v]==-1 | | match (LEFT[V))//Find the augmented path {left[v]=u; return true; }}} return false; }//Returns the maximum number of matches for the current binary graph int solve () {int ans=0;//mostThe large match number for (int i=1;i<=n;i++)//each left node is searched for an augmented path {memset (vis,0,sizeof (VIS)); if (Match (i)) ans++;//finds an augmented path that forms a new match} return ans; }}mm;/*************vecotr Template *****************/
The following is the best perfect match template for binary graphs
#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;const int maxn=100+5;// After reading the contents of the W[MAXN][MAXN] array, call solve (n) to calculate the optimal match for the two graph//But it is necessary to ensure that the graph must have a perfect match//Because this image uses the w[][] to represent a complete graph, there must be a perfectly matched struct max_ match{int w[maxn][maxn],n; W is the weighted matrix, n is the feasible top-mark value of the left and right point set of the size int lx[maxn],ly[maxn];//(bool S[MAXN],T[MAXN]; Mark whether the left and right point set has been accessed int LEFT[MAXN]; Left[i]=j table Right I and left J match, 1 when table no match bool match (int i) {s[i]=true; for (int j=1;j<=n;j++) if (Lx[i]+ly[j]==w[i][j] &&! T[j]) {t[j]=true; if (Left[j]==-1 | | match (LEFT[J])) {left[j]=i; return true; }} return false; }//update the feasible top mark to include more edges coming in void update () {int a=1<<30; for (int i=1;i<=n;i++) if (S[i]) for (int j=1;j<=n;j++) if (! T[j]) {a = min (A,lx[i]+ly[j]-w[i][j]); } for (int i=1;i<=n;i++) {if (s[i]) lx[i]-=a; if (T[i]) ly[i]+=a; }} int solve (int n) {this->n=n; memset (Left,-1,sizeof (left)); for (int i=1;i<=n;i++)//Initialize the feasible top-mark value {lx[i]=ly[i]=0; for (int j=1;j<=n;j++) Lx[i]=max (Lx[i], w[i][j]); } for (int i=1;i<=n;i++) {while (true) {for (int j=1;j<=n;j++) s[j ]=t[j]=false; if (Match (i)) break; else update (); }} int ans=0;//the optimal perfect match for the weights for (int i=1;i<=n;i++) ans+= w[left[i]][i]; return ans; }}km;
The maximum matching problem of binary graphs
POJ 1469COURSES (binary graph Max match): problem Solving report!
POJ 2446Chessboard (binary max match): Checkerboard problem. problem Solving report!
POJ 1274The Perfect Stall (binary graph Max match): problem Solving report!
POJ 1325Machine Schedule (minimum cover number): problem Solving report!
POJ 3692Kindergarten (maximum independent set): problem Solving report!
POJ 2239Selecting Courses (binary graph Max match): problem Solving report!
POJ 2536Gopher II (binary graph Max match): problem Solving report!
POJ 3041Asteroids (minimum cover number): problem Solving report!
POJ 1466Girls and Boys (two-dimensional maximum independent set): problem Solving report!
POJ 1486Sorting Slides (binary graph max match: Key side): problem Solving report!
POJ 2771Guardian of decency (binary graph Max Independent set): problem Solving report!
HDU 1281 Board game (binary chart max match: Key side): problem Solving report!
HDU 2063 roller coaster (binary chart max match: Simple problem): problem Solving report!
HDU 2444The accomodation of Students (binary graph decision + maximum match): problem Solving report!
HDU 3729I ' m telling the Truth (binary graph Max match): problem Solving report!
HDU 3829Cat VS Dog (binary graph Max standalone set): problem Solving report!
HDU 149850 years, colors (min. Minimum coverage): problem Solving report!
HDU 1845Jimmy ' s assignment (binary image matching): problem Solving report!
HDU 4619Warm up 2 (minimum overlay set for two graphs): Problem solving report!
HDU 4185Oil skimming (binary graph Max match): problem Solving report!
HDU 1507Uncle Tom's inherited land* (binary graph max match: Output a set of solutions): problem Solving report!
POJ 3020Antenna Placement (maximum matching of binary graphs): problem Solving report!
POJ 1422Air Raid (dag Minimum Path overlay): problem Solving report!
POJ 3216Repairing Company (floyd+dag Minimum Path overlay): problem Solving report!
POJ 2724Purifying machine (binary graph Max match): problem Solving report!
POJ 1548Robots (Dag Minimum Path overlay): problem Solving report!
HDU 4160Dolls (Dag Minimum Path overlay): problem Solving report!
HDU 1054Strategic Game (minimum overlay set for two graphs): problem Solving report!
HDU 3991Harry Potter and the Present II (floyd+dag Minimum Path overlay): problem Solving report!
POJ 2195Going Home (binary graph best match): Problem solving report!
HDU 2853Assignment (binary graph Best match: Priority with original matching edge): problem Solving report!
HDU 3315My Brute (binary graph Best match: Priority with original matching edge): problem Solving report!
HDU 2255 Ben well-off make a lot of money (binary graph Best match: template problem): problem Solving report!
HDU 2426Interesting Housing problem (binary graph best match): problem Solving report!
HDU 3718Similarity (binary graph best match): problem Solving report!
HDU 1853Cyclic Tour (binary graph best match: Forward loop overlay): problem Solving report!
HDU 2119Matrix (minimum side overlay): problem Solving report!
HDU 1528Card Game cheater (binary graph max match): problem Solving report!
HDU 3722Card Game (binary graph best match): problem Solving report!
HDU 3395Special Fish (best match in binary chart): problem Solving report!
HDU 2448Mining Station on the Sea (floyd+ best match): problem Solving report!
HDU 2282Chocolate (binary graph best match): problem Solving report!
HDU 3488Tour (binary graph best match: Forward loop overlay): problem Solving report!
HDU 3435A New Graph Game (binary graph best match: Forward loop overlay): problem Solving report!
Two-part graph matching