差点翻车
题目
dbzoj
题解
我居然一开始傻逼了
后来发现黑点的x, y连边就是一个二分图,
然后跑最大匹配看看是不是n就行了
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define MAXN (200) using namespace std; int n, link[MAXN + 5], ans; bool vis[MAXN + 5], edg[MAXN + 5][MAXN + 5]; int find(int now) { for (int i = 1; i <= n; i++) if (!vis[i] && edg[now][i]) { vis[i] = true; if (!link[i] || find(link[i])) { link[i] = now; return true; } } return false; } int main() { int t; scanf("%d", &t); while (t--) { memset(link, 0, sizeof(link)); memset(edg, false, sizeof(edg)); scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1, x; j <= n; j++) scanf("%d", &x), edg[i][j] = (x != 0); ans = 0; for (int i = 1; i <= n; i++) { memset(vis, false, sizeof(vis)); if (find(i)) ++ans; } puts((ans == n) ? "Yes" : "No"); } return 0; }
|
By Cansult