Hoj 2801 the maximum matching of the perfect stall Bipartite Graph

Source: Internet
Author: User

 

/*

 

 

 

Question:

 

Every cow prefers to produce milk in different places. Each place can accommodate only one cow.

 

 

 

Analysis:

 

Establish a match between the milk producing place and the cows, and then use Hungry AlgorithmFor example, cows A Like in Q Real estate milk, then

 

G [a] [Q] = true, Create a graph.

 

 

 

*/

 

# Include
<Iostream>

 

# Include
<Cstdio>

 

# Include
<Cstring>

 

Using namespace
STD;

 

# Define x 202

 

Int
XM [X], ym [X], n, m;

 

Bool
G [x] [X], use [x];

 

Int DFS (int u)

 

{

 

For (INT v = 1; v <= m; V ++)

 

If (G [u] [v] &! Use [v])

 

{

 

Use [v] = true;

 

If (ym [v] =-1 | DFS (ym [v])

 

{

 

Ym [v] = u;

 

XM [u] = V;

 

Return true;

 

}

 

}

 

Return false;

 

}

 

Int hungry ()

 

{

 

Memset (XM,-1, sizeof (XM ));

 

Memset (ym,-1, sizeof (ym ));

 

Int ret = 0;

 

For (INT u = 1; U <= N; U ++)

 

If (XM [u] =-1)

 

{

 

Memset (use, false, sizeof (use ));

 

If (DFS (u ))

 

RET ++;

 

}

 

Return ret;

 

}

 

Int main ()

 

{

 

Freopen ("sum. In", "r", stdin );

 

Freopen ("sum. Out", "W", stdout );

 

While (CIN> N> m)

 

{

 

Int T, X;

 

Memset (G, false, sizeof (g ));

 

For (INT I = 1; I <= N; I ++)

 

{

 

Scanf ("% d", & T );

 

While (t --)

 

{

 

Scanf ("% d", & X );

 

G [I] [x] = true;

 

}

 

}

 

Printf ("% d \ n", hungry ());

 

}

 

Return 0;

 

}

 

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.