Title Address: http://poj.org/problem?id=1325
Given a series of tasks, each task is represented by a ternary group (I,X,Y), representing the task I can be done in the X mode of machine A, or in the y mode of machine B. Machines A and B need to be restarted each time the mode is switched. Q. How many times do I need to restart the machine to complete these tasks?
About (I,x,y), from Machine A's X to machine B's Y edge, the problem turns into a minimal vertex overlay problem. Because the minimum vertex cover number of the binary graph = The maximum number of matches, it is possible to find the maximum match.
1#include <cstdio>2#include <iostream>3#include <string.h>4#include <algorithm>5#include <math.h>6#include <stdbool.h>7#include <time.h>8#include <stdlib.h>9#include <Set>Ten#include <map> One#include <stack> A#include <queue> -#include <vector> - using namespacestd; the #defineCLR (x, y) memset (x,y,sizeof (×)) - #defineSQR (x) ((x) * (x)) - #defineRep (i,a,b) for (int i= (a); i<= (b); i++) - #defineLL Long Long + #defineINF 0x3f3f3f3f - #defineA First + #defineB Second A #definePI 3.14159265358979323 at Const intn= -+ One; - intN,m,f[n],g[n][n],link[n]; - - voidInit () - { -CLR (F,0); inCLR (g,0); -CLR (link,-1); to } + - BOOLFindintx) the { * for(intI=1; i<=m;i++) { $ if(!f[i] &&G[x][i]) {Panax Notoginsengf[i]=1; - if(link[i]==-1||find (Link[i])) { thelink[i]=x; + return true; A } the } + } - $ return false; $ } - - intHungary () the { - intans=0;Wuyi for(intI=1; i<=n;i++) { theCLR (F,0); - if(Find (i)) ans++; Wu } - returnans; About } $ - intMain () - { - intu,v,num,k; A + while(~SCANF ("%d",&N)) { the if(!n) Break; - init (); $scanf"%d%d",&m,&k); the while(k--) { thescanf"%d%d%d",&num,&u,&v); theg[u][v]=1; the } -printf"%d\n", Hungary ()); in } the the return 0; About}
[POJ] 1325 machine Schedule (minimum point overlay)