1 #include<cstdio> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 using namespace std; 6 int T,n,map[202][202],dui[202],y[202]; 7 bool zhao(int a1) 8 { 9 for(int i=1;i<=n;i++) 10 if(map[a1][i]&&!y[i]) 11 { 12 y[i]=1; 13 if(!dui[i]||zhao(dui[i])) 14 { 15 dui[i]=a1; 16 return 1; 17 } 18 } 19 return 0; 20 } 21 bool work() 22 { 23 for(int i=1;i<=n;i++) 24 { 25 memset(y,0,sizeof(y)); 26 if(!zhao(i)) 27 return 0; 28 } 29 return 1; 30 } 31 int main() 32 { 33 scanf("%d",&T); 34 for(;T;T--) 35 { 36 memset(map,0,sizeof(map)); 37 memset(dui,0,sizeof(dui)); 38 scanf("%d",&n); 39 for(int i=1;i<=n;i++) 40 for(int j=1;j<=n;j++) 41 { 42 int a1; 43 scanf("%d",&a1); 44 if(a1) 45 map[i][j]=1; 46 } 47 if(work()) 48 printf("Yes\n"); 49 else 50 printf("No\n"); 51 } 52 } 53
二分图匹配,行和列匹配出一条对角线