Title Address: http://acm.hdu.edu.cn/showproblem.php?pid=1068
To find the maximum independent point set of two graphs. Because the maximum independent point set = number of vertices-the maximum number of matches. So the conversion is to find the maximum match. Because the men and women were not given, so everyone used two times, so the result should be divided by 2.
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= -+131; - intN,m,f[n],g[n][n],link[n]; - - voidInit () - { -CLR (F,0); inCLR (g,0); -CLR (link,-1); to } + - BOOLFindintx) the { * for(intI=0; i<n;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 { - intcn1=0;Wuyi for(intI=0; i<n;i++) { theCLR (F,0); - if(Find (i)) ans++; Wu } - returnans; About } $ - intMain () - { - intu,v; A + while(~SCANF ("%d",&N)) { the init (); - for(intI=0; i<n;i++) { $scanf"%d: (%d)",&u,&m); the while(m--){ thescanf"%d",&v); theg[u][v]=1; the } - } inprintf"%d\n", N-hungary ()/2); the } the About return 0; the}
[HDU] 1068 Girls and Boys (two-figure maximum match)