bzoj1059 [ZJOI2007]矩阵游戏
裸的二分图匹配(为什么我要做这种水题?我太弱了QAQ)
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<string> 7 #include<cmath> 8 #include<ctime> 9 #include<queue> 10 #include<stack> 11 #include<map> 12 #include<set> 13 #define rre(i,r,l) for(int i=(r);i>=(l);i--) 14 #define re(i,l,r) for(int i=(l);i<=(r);i++) 15 #define Clear(a,b) memset(a,b,sizeof(a)) 16 #define inout(x) printf("%d",(x)) 17 #define douin(x) scanf("%lf",&x) 18 #define strin(x) scanf("%s",(x)) 19 #define LLin(x) scanf("%lld",&x) 20 #define op operator 21 #define CSC main 22 typedef unsigned long long ULL; 23 typedef const int cint; 24 typedef long long LL; 25 using namespace std; 26 void inin(int &ret) 27 { 28 ret=0;int f=0;char ch=getchar(); 29 while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();} 30 while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar(); 31 ret=f?-ret:ret; 32 } 33 int t,n,pre[222],a[222][222],head[222],next[40040],zhi[40040],ed,bo[222]; 34 void add(int a,int b) 35 { 36 next[++ed]=head[a],head[a]=ed,zhi[ed]=b; 37 } 38 bool find(int x,int t) 39 { 40 for(int i=head[x];i;i=next[i])if(bo[zhi[i]]!=t) 41 { 42 bo[zhi[i]]=t; 43 if(!pre[zhi[i]]||find(pre[zhi[i]],t)) 44 { 45 pre[zhi[i]]=x; 46 return 1; 47 } 48 } 49 return 0; 50 } 51 int main() 52 { 53 inin(t); 54 while(t--) 55 { 56 inin(n);Clear(pre,0),Clear(head,0);ed=0;Clear(bo,0); 57 re(i,1,n)re(j,1,n) 58 { 59 inin(a[i][j]); 60 if(a[i][j]==1)add(i,j); 61 } 62 int ans=0; 63 re(i,1,n)if(find(i,i))ans++; 64 if(ans==n)puts("Yes"); 65 else puts("No"); 66 } 67 return 0; 68 }