https://www.lydsy.com/JudgeOnline/problem.php?id=1059
裸的二分图匹配,行列匹配即可
/************************************************************** Problem: 1059 User: walfy Language: C++ Result: Accepted Time:336 ms Memory:1460 kb ****************************************************************/ //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define vi vector<int> #define mod 1000000009 #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pil pair<int,ll> #define pli pair<ll,int> #define pii pair<int,int> #define cd complex<double> #define ull unsigned long long #define base 1000000000000000000 #define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-12; const int N=200+10,maxn=1000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; int n,a[N][N]; bool used[N]; int color[N]; bool match(int x) { for(int i=1;i<=n;i++) { if(!used[i]&&a[x][i]) { used[i]=1; if(color[i]==-1||match(color[i])) { color[i]=x; return 1; } } } return 0; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&a[i][j]); memset(color,-1,sizeof color); bool ok=1; for(int i=1;i<=n;i++) { memset(used,0,sizeof used); if(!match(i)){ok=0;break;} } if(ok)puts("Yes"); else puts("No"); } return 0; } /*********************** ***********************/