题解;
二分图最大匹配
代码:
#include<bits/stdc++.h> using namespace std; const int N=1e2; int a[N],match[N],c[N][N],f[N],b[N],n,T; int dfs(int x) { for (int i=1;i<=n;i++) if (a[i]&&c[x][i]&&!f[i]) { f[i]=1; if (!match[i]||dfs(match[i])) { match[i]=x; return 1; } } return 0; } int main() { scanf("%d",&T); while (T--) { int ff=0; memset(match,0,sizeof match); scanf("%d",&n); for (int i=1;i<=n;i++)scanf("%d",&a[i]); for (int i=1;i<=n;i++)scanf("%d",&b[i]); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf("%d",&c[i][j]); for (int i=1;i<=n;i++)c[i][i]=1; for (int i=1;i<=n;i++) if (!a[i]||!b[i]) { memset(f,0,sizeof f); if (!dfs(i)) { ff=1; puts("T_T"); break; } } if (!ff)puts("^_^"); } }