Test instructions: Find the fewest points so that all edges are overwritten.
Exercises
Maximum match:
Definition: Give a binary graph, find a maximum number of side matching, that is, select as many edges as possible, so that any two selected edges are not common points. If all points are match points, the match is called a perfect match.
Theorem: Michael Koenig theorem: The number of points covered by the minimum point of the binary graph = the maximum match.
Number of edges covered by minimum path = number of vertices n maximum number of matches
Maximum independent set = minimum path overwrite = number of vertices n maximum number of matches
Augmented road theorem: points that are not contiguous with any matching edges are represented by an open point, and other points match points, that is, the point at which exactly and a matched edge are critical. Never cover points, followed by non-matching edges, matching edges, non-matching edges, matching edges ... The resulting path is called alternating route. Note that if an open point is at the end of the alternate road, this alternate path is called an augmented path. In the augmented path, a non-matching edge is one more than the matching edge. The function of the augmented road is to improve the matching. If there is an augmented path, then the matching and non-matching edges of this path are swapped, resulting in a match more than just one side. Conversely, if the augmentation path is not found, the current match is the maximum match. Finding the augmented path, there is an augmented path to swap the unmatched edges and matching edges on the augmented path, which causes the current maximum number of matches to be +1.
In the binary map, you can distribute the left and right points, or you can mirror all the points so that the maximum match is twice times the normal maximum match.
For example, we can divide the left point (1), the right point (0,2,3), the Connection (1,0) (1,3), the minimum vertex cover is 1
can also be divided into left point (0,1,2,3), right point (0 ', 1 ', 2 ', 3, '), Wired (1,0 ') (0,1 ') ("2,1 ') (1,3 ') (3,1 '), minimum vertex coverage is 1 and 1 '
Code:
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <vector
> #include <algorithm> using namespace std;
const int maxn=1510;
int n;
int pre[maxn];//Save the points of the match point int vis[maxn];
Vector<int> E[MAXN];
int find (int u)//Determine if there is an augmented path, there is a return of 1 {int i,v;
For (I=0;i<e[u].size (); i++) {v=e[u][i];
if (Vis[v]) continue;
Vis[v]=1; if (pre[v]==-1| |
Find (Pre[v])//Locate an open point, or an augmented path.
{pre[v]=u;//matching Edge and non-matching edge exchange return 1;
}} return 0;
} int main () {while (scanf ("%d", &n)!=eof) {int i,j,k,a,b,c,m;
memset (pre,-1,sizeof (pre));
for (i=0;i<n;i++) e[i].clear ();
for (i=0;i<n;i++) {scanf ("%d: (%d)", &a,&m);
for (j=0;j<m;j++) {scanf ("%d", &b);
E[a].push_back (b);
E[b].push_back (a);
}} int ans=0; for (i=0;i<n;i++) {memset (vis,0,sizeof (VIS));
Ans+=find (i);
} printf ("%d\n", ANS/2);
} return 0;
}