I began to misunderstand the meaning of the question and thought that the audience should meet both conditions. Later, I can see the report on understanding the question. When the audience wants to leave their pets out, the audience thinks they will leave.
The audience is divided into two sets by cat_lover and dog_lover. If there is a conflict between the two sets, the two vertices are connected, the edges represent a conflict, and then the largest independent set is obtained.
Maximum Independent Set = number of vertices-minimum vertex overwrite (maximum matching)
# Include <iostream> using namespace STD; const int n = 505; struct option {char a [5], B [5] ;}; int maze [N] [N]; option cat [N], dog [N]; int isvisit [N]; int match [N]; int C, D, V; int cnt_cat, cnt_dog; bool find (int u) {for (INT I = 0; I <cnt_dog; I ++) if (maze [u] [I] &! Isvisit [I]) {isvisit [I] = true; If (Match [I] =-1 | find (Match [I]) {match [I] = u; return true ;}} return false ;}int main () {INT cases; char a [5]; char B [5]; scanf ("% d", & cases); While (cases --) {scanf ("% d", & C, & D, & V ); cnt_cat = 0; cnt_dog = 0; For (INT I = 0; I <v; I ++) {scanf ("% S % s", a, B ); if (A [0] = 'C') {strcpy (cat [cnt_cat]. a, a); strcpy (cat [cnt_cat]. b, B); cnt_cat ++;} else {strcpy (DOG [cnt_dog]. a, a); strcpy (DOG [cnt_dog]. b, B); cnt_dog ++ ;}} memset (maze, false, sizeof (maze); For (INT I = 0; I <cnt_cat; I ++) for (Int J = 0; j <cnt_dog; j ++) if (strcmp (cat [I]. a, dog [J]. b) = 0 | strcmp (cat [I]. b, dog [J]. a) = 0) maze [I] [J] = true; int ans = 0; memset (match,-1, sizeof (MATCH )); for (INT I = 0; I <cnt_cat; I ++) {memset (isvisit, false, sizeof (isvisit); If (find (I) ans ++ ;} printf ("% d \ n", V-ans);} return 0 ;}