Poj 1325 Machine Schedule -- minimum vertex Overwrite

Source: Internet
Author: User

[Cpp]
/*
Machine A has n (0 ~ N-1) mode. Machine B has m (0 ~ M-1) Mode
There are k tasks to be done first, which can be done in ai mode of machine A or bi mode of machine B.
The task has no order. Restart in the order of mode. Both machines start in the Mode 0.
 
How many times does it need to be restarted?
 
Minimum vertex coverage in a Bipartite Graph
 
The mode of A is set X, and the mode of B is set Y.
 
Edge creation by task
 
Minimum vertex coverage
 
The task is to find the minimum number of reboots, that is, to work in at least several modes (except for the 0 mode)
You only need to select any endpoint of the edge.
 
Therefore, finding the minimum point to cover these points captures all the edges and completes all the tasks in the set. The mode is the pattern represented by this store.
 
Minimum vertex overwrite = maximum matching of a Bipartite Graph
*/
# Include <stdio. h>
# Include <vector>
Using namespace std;
Int n, m, k;
Vector <int> v [201];
Int vis [201];
Int match [201];
Int dfs (int I)
{
For (int j = 0; j <v [I]. size (); ++ j)
{
If (! Vis [v [I] [j] + n]) // + n is the adjustment number.
{
Vis [v [I] [j] + n] = 1;
If (match [v [I] [j] + n] =-1 | dfs (match [v [I] [j] + n])
{
Match [v [I] [j] + n] = I;
Return 1;
}
}
}
Return 0;
}
Int main ()
{
Int I, a, B, c;
While (scanf ("% d", & n), n)
{
Scanf ("% d", & m, & k );
For (I = 0; I <= m + n; ++ I)
V [I]. clear ();
For (I = 1; I <= k; ++ I)
{
Scanf ("% d", & a, & B, & c );
If (B & c)
V [B]. push_back (c); // you only need to point from X set to Y set.
}
A = 0; // matching part
Memset (match,-1, sizeof (match ));
For (I = 1; I <= n; I ++)
{
Memset (vis, 0, sizeof (vis ));
If (dfs (I ))
A ++;
}////
Printf ("% d \ n", );
}
Return 0;
}
Author: qq172108805

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.