标签:des style blog http color java os io
7 0: (3) 4 5 6 1: (2) 4 6 2: (0) 3: (0) 4: (2) 0 1 5: (1) 0 6: (2) 0 1 3 0: (2) 1 2 1: (1) 0 2: (1) 0
5 2
解题:找出相互没关系的一个人数最大的集合。首先,是点!让点多,我们可以求点小!最小点覆盖!那么我们可以求最大匹配数!无向图的最大匹配数要处以2.。。。就这样了
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 1005; 18 struct arc{ 19 int to,next; 20 }; 21 arc g[200100]; 22 int head[maxn],from[maxn],tot,n; 23 bool vis[maxn]; 24 void add(int u,int v){ 25 g[tot].to = v; 26 g[tot].next = head[u]; 27 head[u] = tot++; 28 } 29 bool dfs(int u){ 30 for(int i = head[u]; i != -1; i = g[i].next){ 31 if(!vis[g[i].to]){ 32 vis[g[i].to] = true; 33 if(from[g[i].to] == -1 || dfs(from[g[i].to])){ 34 from[g[i].to] = u; 35 return true; 36 } 37 } 38 39 } 40 return false; 41 } 42 int main() { 43 int i,j,k,u,v,ans; 44 while(~scanf("%d",&n)){ 45 memset(head,-1,sizeof(head)); 46 memset(from,-1,sizeof(from)); 47 tot = 0; 48 for(i = 0; i < n; i++){ 49 scanf("%d: (%d)",&j,&k); 50 for(j = 0; j < k; j++){ 51 scanf("%d",&v); 52 add(i,v); 53 add(v,i); 54 } 55 } 56 for(ans = i = 0; i < n; i++){ 57 memset(vis,false,sizeof(vis)); 58 if(dfs(i)) ans++; 59 } 60 ans >>= 1; 61 printf("%d\n",n-ans); 62 } 63 return 0; 64 }
BNUOJ 1585 Girls and Boys,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/crackpotisback/p/3907066.html