Question:
There is a TV program called "Cat vs Dog ".. every guest will either like a dog or a cat or a dog .. ask how to arrange for the most guests to be satisfied with cats and dogs )..
Question:
This question gives us a better understanding of the Maximum Independent Set of the Bipartite Graph .. in turn .. divide the audience into two parts .. some like cats and some like dogs .. there is a conflict between the two audiences .. obtain the Maximum Independent Set (N-maximum matching ).. we get the most vertices without edges .. according to the relationship of the diagram .. the number of these points is the answer...
This type of problem can be summarized as follows: the graph is a bipartite graph, and there are some point-to-point conflicts. The most commonly found points make it non-contradictory...
Program:
#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<stack>#include<string.h>#include<queue>#define ll long long#define esp 1e-5#define MAXN 505#define MAXM 50000000#define oo 100000007using namespace std; int n,match[MAXN],P[MAXN][2],color[MAXN];bool used[MAXN],g[MAXN][MAXN];bool dfs(int x){ for (int i=1;i<=n;i++) if (g[x][i] && !used[i]) { used[i]=true; if (!match[i] || dfs(match[i])) { match[i]=x; return true; } } return false;}int getmax(){ int sum=0; memset(match,0,sizeof(match)); for (int i=1;i<=n;i++) if (color[i]==1) { memset(used,false,sizeof(used)); sum+=dfs(i); } return sum;}int main() { int cases,C,D,i,x,y; char c; scanf("%d",&cases); while (cases--) { scanf("%d%d%d",&C,&D,&n); for (i=1;i<=n;i++) { do { c=getchar(); }while (c!='C' && c!='D'); scanf("%d",&x); if (c=='D') x+=C,color[i]=2; else color[i]=1; do { c=getchar(); }while (c!='C' && c!='D'); scanf("%d",&y); if (c=='D') y+=C; P[i][0]=x,P[i][1]=y; } memset(g,false,sizeof(g)); for (x=1;x<=n;x++) if (color[x]==1) for (y=1;y<=n;y++) if (P[x][0]==P[y][1] || P[y][0]==P[x][1]) g[x][y]=true; printf("%d\n",n-getmax()); } return 0; }