题意:一些 boys 和girls 有暧昧关系,我们要选出 一些人,这些人 任意两个人之间没有暧昧 关系,求最多可以选出 多少人。
题解:
最大独立集,这里建的是双向图,所以,最大匹配要除以 2;
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<iostream> 5 #include<algorithm> 6 #include< set> 7 #include<map> 8 #include<queue> 9 #include<vector> 10 #include< string> 11 #define Min(a,b) a<b?a:b 12 #define Max(a,b) a>b?a:b 13 #define CL(a,num) memset(a,num,sizeof(a)); 14 #define eps 1e-6 15 #define inf 10001000 16 17 #define ll __int64 18 19 #define read() freopen("data.txt","r",stdin) ; 20 const double pi = acos(- 1.0); 21 const int maxn = 510; 22 23 using namespace std; 24 int n; 25 int mat[maxn][maxn],result[maxn],vis[maxn] ; 26 27 int find( int a) 28 { 29 int i ; 30 for(i = 0 ; i < n;i++) 31 { 32 if(mat[a][i]&&!vis[i]) 33 { 34 vis[i] = 1; 35 if(result[i] == 0||find(result[i])) 36 { 37 result[i] = a ; 38 return 1 ; 39 40 } 41 } 42 } 43 return 0 ; 44 } 45 46 int main() 47 { 48 // read(); 49 int cas = 0,i ,a,num,b; 50 while(scanf( " %d ",&n)!=EOF) 51 { 52 CL(result, 0); 53 CL(mat, 0) ; 54 for(i = 0 ; i < n;i++) 55 { 56 scanf( " %d: (%d) ",&a,&num); 57 while(num--) 58 { 59 scanf( " %d ",&b); 60 mat[a][b] = 1; 61 } 62 } 63 int ans = 0 ; 64 for(i = 0 ;i < n;i++) 65 { 66 CL(vis, 0); 67 if(find(i))ans++; 68 } 69 70 printf( " %d\n ",n - ans/ 2); 71 } 72 }