The main topic: There are two machines, a machine has n mode of operation, B machine has m mode of operation, just started two machines are 0 mode. If you want to switch mode, the machine must be restarted.
There are k tasks, each task can be handed to the a machine I mode or B machine's J mode complete, ask how many times to restart the machine to complete the task
Problem-solving ideas: Two machine points are divided into two point sets. The relationship between point sets is a task. You want to finish all the tasks. It is necessary to cover all the edges, so the minimum point is covered.
Here's a point to note. Assuming that all tasks have a 0, then the machine does not have to restart, the number of restarts is 0 (since the beginning is 0)
#include <cstdio>#include <vector>#include <cstring>using namespace STD;Const intN = the;intN, M, K;intVis[n], link[n];BOOLFlag vector<int>G[n];voidInit () { for(inti =1; I < n; i++) g[i].clear ();intX, y, Z; for(inti =0; I < K; i++) {scanf("%d%d%d", &x, &y, &z);if(Y * z = =0)Continue; G[y].push_back (z); }memset(Link,-1,sizeof(link));}BOOLDfsintu) { for(inti =0; I < g[u].size (); i++) {intv = g[u][i];if(Vis[v])Continue; VIS[V] =1;if(Link[v] = =-1|| DFS (Link[v])) {Link[v] = u;return true; } }return false;}voidHungary () {intAns =0; for(inti =1; I < n; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", ans);}intMain () { while(scanf("%d", &n)! = EOF && N) {scanf("%d%d", &m, &k); Init (); Hungary (); }return 0;}
POJ-1325 Machine Schedule The minimum point coverage of the binary diagram