讲真不能再裸的二分图匹配
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
// <1433.cpp> - Tue Aug 16 22:07:14 2016 // This file is created by XuYike's black technology automatically. // Copyright (C) 2015 ChangJun High School, Inc. // I don't know what this program is. #include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <cstdio> #include <cmath> using namespace std; typedef long long lol; int gi(){ int res=0,fh=1;char ch=getchar(); while((ch>'9'||ch<'0')&&ch!='-')ch=getchar(); if(ch=='-')fh=-1,ch=getchar(); while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar(); return fh*res; } const int MAXN=210; const int MAXM=10010; const int INF=1e9; bool a[60]; int bt,b[MAXN],next[MAXM],to[MAXM],val[MAXM]; inline void add(int x,int y,int v){ next[++bt]=b[x];b[x]=bt;to[bt]=y;val[bt]=v; next[++bt]=b[y];b[y]=bt;to[bt]=x;val[bt]=0; } int T,dis[MAXN],q[MAXN]; inline bool fc(){ for(int i=1;i<=T;i++)dis[i]=0; dis[0]=1; int l=1,r=1;q[1]=0; while(l<=r){ int now=q[l++]; for(int i=b[now];i;i=next[i]) if(val[i]&&!dis[to[i]]){ dis[to[i]]=dis[now]+1; if(to[i]==T)return 1; q[++r]=to[i]; } } return 0; } int dfs(int x,int M){ if(x==T)return M; int ans=0; for(int i=b[x];i;i=next[i]) if(val[i]&&dis[to[i]]==dis[x]+1){ int now=dfs(to[i],min(M-ans,val[i])); val[i]-=now; val[i^1]+=now; if((ans+=now)==M)return ans; } dis[x]=-1; return ans; } int main(){ int t=gi(); while(t--){ int n=gi(),tot=0,ans=0;T=n<<1|1; for(int i=0;i<=T;i++)b[i]=0;bt=1; for(int i=1;i<=n;i++)if(a[i]=gi())add(n+i,T,1); for(int i=1;i<=n;i++)if(!(a[i]&=gi()))add(0,i,1),tot++; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)if(gi()||i==j)add(i,n+j,1); while(fc())ans+=dfs(0,INF); puts(ans==tot?"^_^":"T_T"); } return 0; } |