The Hungarian algorithm of binary graph
The difficulty of the dichotomy chart is mainly under construction;
Some important formulae about the two-part graph:
Maximum number of matches = minimum point coverage
Minimum edge overlay = Total number of vertices-maximum number of matches/2 (this to be split: UN=VN=CNT,ANS=CNT-HUNGARY/2)
Maximum group = maximum independent set of complement graphs
Maximum independent set = number of vertices-maximum match
Hungarian algorithm:
intLink[maxn];vector<int>G [MAXN];intun,vn;BOOLVIS[MAXN];BOOLDfsintu) { for(intI=0; I<g[u].size (); i++) {//Remove the next non-visited point of U v intv=G[u][i]; if(!Vis[v]) {Vis[v]=1; if(link[v]==-1|| DFS (Link[v])) {//if Link[v]==-1 or Dfs (Link[v]), invert: link[v]=u;link[v]=u; return true; } } } return false;}intHungary () {intres=0; memset (Link,-1,sizeof(link));//initializing the link array for(intu=1; u<=un;u++) {memset (Vis,0,sizeof(VIS));//Note each time you need to initialize the VIS array if(Dfs (U)) res++; } returnRes;}
Hungary Algorithm
Using vector instead of adjacency matrix to simulate adjacency table, increase the efficiency without increasing the amount of code (in fact, I have not mastered the adjacency table.) )
Binary graph (Hungarian algorithm)