Cats and dogs
Memory limit: 128 MiB time limit: 1000 ms standard output
Title Description
Input Format
Output Format
Sample
Data range and tips
#include<bits/stdc++.h> using namespace std; int n,m,question,catnum,dognum; int a[601][601],result[20000],tot=0; int id[601][601]; bool state[1000]; bool find(int aa) { for(int j=1;j<=n;j++) if(a[aa][j]==1&&state[j]==0) { state[j]=1; if(result[j]==0||find(result[j])) { result[j]=aa; return 1; } } return 0; } int main() { cin>>catnum>>dognum>>n; int x,y; string aa[600],bb[600]; for(int i=1;i<=n;i++) { cin>>aa[i]; cin>>bb[i]; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(aa[i]==bb[j]) a[i][j]=a[j][i]=1; } for(int i=1;i<=n;i++) { memset(state,0,sizeof(state)); if(find(i)) tot++; } cout<<n-tot/2<<endl; }
The system brushed up bipartite graph, that this question quite value
We will build a contradiction between man's sides, then you can seek out the smallest independent set