题解:
对于每两个不认识的建边
然后求最大都立集
代码:
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int N=205; int n,m,k,a[N][N],match[N],f[N],x,y,cas; int dfs(int x) { for (int i=1;i<=m;i++) if (!a[x][i]&&!f[i]) { f[i]=1; if (!match[i]||dfs(match[i])) { match[i]=x; return 1; } } return 0; } int main() { while (~scanf("%d%d%d",&n,&m,&k),n||m||k) { memset(a,0,sizeof a); printf("Case %d: ",++cas); memset(match,0,sizeof match); while (k--)scanf("%d%d",&x,&y),a[x][y]=1; int ans=0; for (int i=1;i<=n;i++) { memset(f,0,sizeof f); ans+=dfs(i); } printf("%d ",n+m-ans); } }