Binary graph (Hungarian algorithm)

Source: Internet
Author: User

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)

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.