[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