Obtain the maximum matching value of a bipartite graph.

Source: Internet
Author: User
Always search for whether there is a wrong link in the bipartite graph. If yes, increase the number of matches by 1.
The link starts at the left and ends at the left. The path length is an odd number, and the first and last line segments do not match. In this way, if there is a wrong link, there must be another match that is 1 longer than the original one.

Flag indicates whether the current vertex has been accessed, and link indicates the precursor of the vertex after the link is handed in the wrong link.

Bool source [110] [310], flag [310];
Int _ link [310], p, N;

Bool find (int)
{
Int I, J, K;
For (I = 1; I <= N; I ++)
{
If (source [a] [I] = 1 & flag [I] = 0)
{
Flag [I] = 1;
If (_ link [I] = 0 | find (_ link [I])
{
_ Link [I] =;
Return true;
}
}
}
Return false;
}

Int main ()
{
Input Source; mount = 0;
For (I = 1; I <= P; I ++)
{
Memset (flag, 0, sizeof (FLAG ));
If (find (I) Mount ++;
}
Cout <Mount <Endl;
}

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.