#include <bits/stdc++.h>
using namespace std;
const int nmax = 250;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef double db;
int t, n, cy[nmax];
bool mp[nmax][nmax];
bool visit[nmax];
bool findpath(int x) {
for (int i = 1; i <= n; ++i) {
if (mp[x][i] && !visit[i]) {
visit[i] = true;
if (!cy[i] || findpath(cy[i])) {
cy[i] = x;
return true;
}
}
}
return false;
}
bool matchmax() {
for (int i = 1; i <= n; ++i) {
memset(visit, 0, sizeof visit);
if (!findpath(i)) return 0;
}
return 1;
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
memset(cy, 0, sizeof(cy));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
scanf("%d", &mp[i][j]);
}
}
if (matchmax()) printf("Yes\n");
else printf("No\n");
}
return 0;
}
BZOJ [ZJOI2007]矩阵游戏 (二分图匹配)
最新推荐文章于 2019-05-02 23:10:00 发布