http://acm.hdu.edu.cn/showproblem.php?pid=1150
There are two kinds of machines, a machine has n mode, B machine has M mode, now have K tasks need to execute, do not switch a task machine will need to reboot once,
If task I is performed on machine A, a machine needs a corresponding pattern a, and if executed on machine B, machine A needs a pattern B.
Always is machine A in switch mode, now lets you arrange a reasonable task execution order, so that the machine restarts the fewest number of times.
An edge is attached to each task. Two the minimum vertex overlay is the least points that can be connected to all the edges and then converted to the maximum match.
The problem is that the initial state is 0, so if there is a task with a vertex of 0, there is no need to join because there is no cost.
1#include <cstdio>2#include <cstring>3#include <vector>4 using namespacestd;5 Const intMAXN = the;6 intn,m,k;7vector<int>G[MAXN];8 intLINK[MAXN];9 BOOLVIS[MAXN];Ten One voidAdd_edge (intUintv) A { - G[u].push_back (v); - //g[v].push_back (u); the } - - BOOLDfsintu) - { + for(intI=0; I<g[u].size (); i++) - { + intv=G[u][i]; A if(!Vis[v]) at { -vis[v]=true; - if(link[v]==-1||DFS (Link[v])) - { -link[v]=u; - return true; in } - } to } + return false; - } the intMain () * { $ //freopen ("A.txt", "R", stdin);Panax Notoginseng inta,b,c; - while(~SCANF ("%d", &n) &&N) the { +scanf"%d%d",&m,&k); A for(intI=0; i<maxn;i++) g[i].clear (); the for(intI=0; i<k;i++) + { -scanf"%d%d%d",&a,&b,&c); $ if(b>0&&c>0) $ Add_edge (b,c); - } - intans=0; thememset (link,-1,sizeof(link)); - for(intI=0; i<n;i++)Wuyi { thememset (Vis,0,sizeof(Vis)); - if(Dfs (i)) ans++; Wu } -printf"%d\n", ans); About } $ return 0; -}
hdu-1150 machine Schedule (binary graph matching minimum point coverage)