标签:
http://acm.hdu.edu.cn/showproblem.php?pid=1068
因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数)
2U=2V-2M 所以 U=n-M‘/2. (没怎么看明白) 但是不这样会wa.
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <vector> 5 #include <cstring> 6 #include <string> 7 #include <algorithm> 8 #include <string> 9 #include <set> 10 #include <functional> 11 #include <numeric> 12 #include <sstream> 13 #include <stack> 14 #include <map> 15 #include <queue> 16 #pragma comment(linker, "/STACK:102400000,102400000") 17 #define CL(arr, val) memset(arr, val, sizeof(arr)) 18 19 #define ll long long 20 #define inf 0x7f7f7f7f 21 #define lc l,m,rt<<1 22 #define rc m + 1,r,rt<<1|1 23 #define pi acos(-1.0) 24 25 #define L(x) (x) << 1 26 #define R(x) (x) << 1 | 1 27 #define MID(l, r) (l + r) >> 1 28 #define Min(x, y) (x) < (y) ? (x) : (y) 29 #define Max(x, y) (x) < (y) ? (y) : (x) 30 #define E(x) (1 << (x)) 31 #define iabs(x) (x) < 0 ? -(x) : (x) 32 #define OUT(x) printf("%I64d\n", x) 33 #define lowbit(x) (x)&(-x) 34 #define Read() freopen("a.txt", "r", stdin) 35 #define Write() freopen("b.txt", "w", stdout); 36 #define maxn 1000000000 37 #define N 510 38 #define mod 1000000000 39 using namespace std; 40 41 vector<int>G[N]; 42 int link[N]; 43 bool vis[N]; 44 45 bool dfs(int u) 46 { 47 for(int i=0;i<G[u].size();i++) 48 { 49 int v=G[u][i]; 50 if(!vis[v]) 51 { 52 vis[v]=true; 53 if(link[v]==-1||dfs(link[v])) 54 { 55 link[v]=u; 56 return true; 57 } 58 } 59 } 60 return false; 61 } 62 int main() 63 { 64 //Read(); 65 int n,a,b,c; 66 while(~scanf("%d",&n)) 67 { 68 for(int i=0;i<n;i++) G[i].clear(); 69 for(int i=0;i<n;i++) 70 { 71 scanf("%d: (%d)",&a,&b); 72 // printf("%d %d\n",a,b); 73 for(int i=0;i<b;i++) 74 { 75 scanf("%d",&c); 76 G[a].push_back(c); 77 } 78 } 79 int ans=0; 80 memset(link,-1,sizeof(link)); 81 for(int i=0;i<n;i++) 82 { 83 memset(vis,0,sizeof(vis)); 84 if(dfs(i)) ans++; 85 } 86 printf("%d\n",n-ans/2); 87 } 88 return 0; 89 }
hdu - 1068 Girls and Boys (二分图最大独立集+拆点)
标签:
原文地址:http://www.cnblogs.com/nowandforever/p/4601126.html