"Hiho" Hiho 31st week two maximum match, some of the basic conclusions will be updated here

Source: Internet
Author: User

Test instructions

Maximum matching of binary graphs

Ideas:

The maximum matching algorithm of binary graph is the Hungarian algorithm, which is similar to the finding of the augmented path in the network flow.

Personal preference Dfs Version = =

At that time also look at Kuangbin big template just gradually groping

Supplemental Definitions and theorems:

Maximum matches: the number of matching edges that match the maximum
minimum Point coverage : Select a minimum point so that at least one end of any edge is selected
maximum independent number : Select the most points so that any selected two points are not connected
Minimum path coverage : For a DAG (directed acyclic graph), select the fewest paths so that each vertex belongs to and belongs to only one path. The path length can be 0 (that is, a single point).

Theorem 1: Maximum number of matches = minimum point coverage (this is the Konig theorem)
Theorem 2: Maximum number of matches = maximum Independent number
Theorem 3: Minimum path coverage = number of vertices-maximum number of matches

Note that the maximum matching number of the graph is divided by 2, because it is a graph without direction!

Attached code:

#include <iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<string>#include<math.h>#include<stack>#include<queue>#include<vector>#include<map>#include<Set>#pragmaWarning (disable:4996)#defineZero (a) memset (a, 0, sizeof (a))#defineNeg (a) memset (a,-1, sizeof (a))#defineAll (a) A.begin (), A.end ()#definePB push_back#defineREPF (i,a,b) for (i = a;i <= b; i++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1#defineRoot 1,n,1#defineLD RT << 1#defineRd RT << 1 | 1#definell Long Long#defineMAXN 1005#defineMoD 10007using namespacestd;intLINKER[MAXN];BOOLUsed[maxn];vector<int>MP[MAXN];intUN;BOOLDfsintu) {     for(inti =0; I<mp[u].size (); i++){        if(!Used[mp[u][i]]) {Used[mp[u][i]]=true; if(Linker[mp[u][i]] = =-1||DFS (Linker[mp[u][i])) {Linker[mp[u][i]]=u; return true; }        }    }    return false;}intHungary () {intu; intres =0; MEMSET (linker,-1,sizeof(linker));  for(U =1; U <= UN; u++) {memset (used,false,sizeof(used)); if(Dfs (U)) res++; }    returnRes;}intMain () {intK;  while(~SCANF ("%d%d", &un, &k)) {         for(inti =1; I <= UN; ++i)        {mp[i].clear (); }        intu, v;  while(k--) {scanf ("%d%d", &u, &v);            Mp[u].push_back (v);        Mp[v].push_back (U); } printf ("%d\n%d\n", Hungary ()/2, Un-hungary ()/2); }    return 0;}

"Hiho" Hiho 31st week two maximum match, some of the basic conclusions will be updated here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.