Want to see more problem-solving reports:Http://blog.csdn.net/wangjian8006/article/details/7870410
Reprinted please indicate the source:Http://blog.csdn.net/wangjian8006
There are two machines a and B, machine A has n modes, machine B has m modes, and two machines are initially in 0 mode.
Then there are K jobs. Each job has three parameters I, A, and B.
I indicates the job number. A and B indicate that the I job is completed either in the mode of machine A or in the B mode of machine B.
How many times can the two machines perform at least one transformation?
Solution: The minimum point coverage of a Binary Graph
Create a bipartite graph with n vertices on the left and N vertices on the left.
The right side represents the machine B, M points, and m modes.
Now, for each job, I, A, and B, point A on the left is directed to point B on the right.
In this way, if we want to finish all the jobs, do we need to find the smallest vertex to overwrite all the edges?
Then, the minimum vertex overwrite is equal to the maximum match.
If you are not clear, draw a sample.
/* Memory 212 ktime 32 Ms */# include <iostream> using namespace STD; # define maxv 110int n, m, K; int map [maxv] [maxv]; int link [maxv], use [maxv]; int DFS (int x) {int I, j; for (I = 1; I <= m; I ++) if (Map [x] [I] &! Use [I]) {J = link [I]; use [I] = 1; Link [I] = X; if (j =-1 | DFS (j) return true; Link [I] = J;} return false;} int Hungary () {int num = 0; int I, j; memset (link,-1, sizeof (Link); for (I = 1; I <= N; I ++) {for (j = 1; j <= m; j ++) use [J] = 0; If (DFS (I) num ++;} return num ;} int main () {int, b, C, I; while (scanf ("% d", & N) {scanf ("% d", & M, & K ); memset (MAP, 0, sizeof (MAP); for (I = 0; I <K; I ++) {scanf ("% d ", & A, & B, & C); map [B] [C] = 1;} printf ("% d \ n", Hungary ();} return 0 ;}