The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislike-animal, if the child's like-animal is a cat, then his/hers dislike-animal must be a dog, and vice versa.
Now the zoo administrator is removing some animals, if one child's like-animal is not removed and his/hers dislike-animal is removed, he/she will be happy. So the administrator wants to know which animals he should remove to make maximum number of happy children.
Now the zoo administrator is removing some animals, if one child's like-animal is not removed and his/hers dislike-animal is removed, he/she will be happy. So the administrator wants to know which animals he should remove to make maximum number of happy children.
InputThe input file contains multiple test cases, for each case, the first line contains three integers N <= 100, M <= 100 and P <= 500.
Next P lines, each line contains a child's like-animal and dislike-animal, C for cat and D for dog. (See sample for details)
OutputFor each case, output a single integer: the maximum number of happy children.Sample Input
1 1 2
C1 D1
D1 C1 1 2 4
C1 D1
C1 D1
C1 D2
D2 C1
Sample Output
1
3
Hint
Case 2: Remove D1 and D2, that makes child 1, 2, 3 happy.
题意:动物园有猫和狗,一个孩子有喜欢和不喜欢的动物,喜欢猫就一定讨厌狗,反之亦然,现可拿走动物使孩子最高兴
题解:最大独立集,二分图的最大独立集=顶点数-二分图最大匹配,接下来就是建图,把孩子当作点,如果某个孩子喜欢的动物是另一个讨厌的,那么就连边
我们希望减少最小的孩子数来满足所有人的喜好,这就是最小点覆盖。
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=0x3f3f3f3f; int n,m,p,color[N];
bool used[N],ok[N][N];
struct edge{
string a,b;
}e[N]; bool match(int x)
{
for(int i=;i<=p;i++)
{
if(!used[i]&&ok[x][i])
{
used[i]=;
if(color[i]==-||match(color[i]))
{
color[i]=x;
return ;
}
}
}
return ;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
while(cin>>n>>m>>p){
memset(ok,,sizeof ok);
for(int i=;i<=p;i++)
{
cin>>e[i].a>>e[i].b;
e[i].id=i;
}
for(int i=;i<=p;i++)
for(int j=;j<=p;j++)
if(e[i].a==e[j].b||e[i].b==e[j].a)
ok[i][j]=ok[j][i]=;
/* for(int i=1;i<=p;i++)
{
for(int j=1;j<=p;j++)
cout<<ok[i][j];
cout<<endl;
}*/
int ans=;
memset(color,-,sizeof color);
for(int i=;i<=p;i++)
{
memset(used,,sizeof used);
ans+=match(i);
}
cout<<p-ans/<<endl;
}
return ;
}