BZOJ 1059 二分图匹配

思路:
对于读入的矩阵
直接跑一遍匈牙利就好了

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int T,n,a[222][222],vis[222],match[222];
bool dfs(int x){
    for(int i=1;i<=n;i++)
        if(a[x][i]&&!vis[i]){
            vis[i]=1;
            if(match[i]==-1||dfs(match[i])){
                match[i]=x;return 1;
            }
        }
    return 0;
}
int main(){
    scanf("%d",&T);
    while(T--){
        memset(match,-1,sizeof(match));
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                scanf("%d",&a[i][j]);
        for(int i=1;i<=n;i++){
            memset(vis,0,sizeof(vis));
            if(!dfs(i)){
                puts("No");goto st;
            }
        }
        puts("Yes");
        st:;
    }
}

这里写图片描述

原文地址:https://www.cnblogs.com/SiriusRen/p/6532259.html