题意:男女关系,求大的集合满足没人有关系
解法:最大独立点集
- 顶点数和-最大匹配
- 因为建立的二倍图比如 1匹配3' 那么3必然匹配1' 所以顶点数减去匹配/2
-
-
-
-
-
-
-
- #include<iostream>
- #include<cstring>
- #include <algorithm>
- #include<cstdlib>
- #include<vector>
- #include<cmath>
- #include<stdlib.h>
- #include<iomanip>
- #include<list>
- #include<deque>
- #include<map>
- #include <stdio.h>
- #include <queue>
-
- const int maxn=1000+5;
-
- #define inf 0x3f3f3f3f
- #define INF 0x3FFFFFFFFFFFFFFFLL
- #define rep(i,n) for(i=0;i<n;i++)
- #define reP(i,n) for(i=1;i<=n;i++)
-
- #define ull unsigned long long
- #define ll long long
-
- #define cle(a) memset(a,0,sizeof(a))
-
- using namespace std;
- bool bmap[maxn][maxn];
- bool bmask[maxn];
- int n;
- int cx[maxn],cy[maxn];
- int findpath(int u){
- int i,j;
- rep(i,n)if(bmap[u][i]&&!bmask[i]){
- bmask[i]=1;
- if(cy[i]==-1||findpath(cy[i])){
- cy[i]=u;cx[u]=i;return 1;
- }
- }
- return 0;
- }
- int maxmatch(){
- int res=0;
- int i,j;
- rep(i,n)cx[i]=-1,cy[i]=-1;
- rep(i,n)if(cx[i]==-1){
- rep(j,n)bmask[j]=0;
- res+=findpath(i);
- }
- return res;
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("in.txt","r",stdin);
-
- #endif
- char str[5];
- while(cin>>n)
- {
- cle(bmap);
- int t,u,v;int i;
- rep(i,n){
- scanf("%d: (%d)",&u,&t);
- while(t--)
- {
- scanf("%d",&v);
- bmap[u][v]=1;
- }
- }
- cout<<n-maxmatch()/2<<endl;
- }
- return 0;
- }