bzoj1059 矩阵游戏
震惊地发现自己不会匈牙利了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//Twenty
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int N=299*2;
int T,n,x,a[N][N],vis[N],pre[N];
int find(int x){
for(int i=1;i<=n*2;i++)
if(a[x][i]&&!vis[i]) {
vis[i]=1;
if(!pre[i]||find(pre[i])) {
pre[i]=x;
return 1;
}
}
return 0;
}
int main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(pre,0,sizeof(pre));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) {
scanf("%d",&x);
if(x) a[i][n+j]=a[n+j][i]=1;
}
int ans=0;
for(int i=1;i<=n;i++) {
memset(vis,0,sizeof(vis));
if(find(i)) ans++;
}
if(ans>=n) printf("Yes\n");
else printf("No\n");
}
return 0;
}