[ZJOI2007]矩阵游戏
#include <iostream>
#include <cstring>
using namespace std;
const int N = 210;
int n;
bool g[N][N], st[N];
int match[N];
bool find(int x)
{
for(int i = 1; i <= n; i ++)
{
if(g[x][i] && !st[i])
{
st[i] = true;
if(!match[i] || find(match[i]))
{
match[i] = x;
return true;
}
}
}
return false;
}
bool solve()
{
memset(match, 0, sizeof match);
cin >> n;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
cin >> g[i][j];
for(int i = 1; i <= n; i ++)
{
memset(st, 0, sizeof st);
if(!find(i)) return false;
}
return true;
}
int main()
{
int t;
cin >> t;
while(t --)
{
if(solve()) puts("Yes");
else puts("No");
}
return 0;
}