显示代码纯文本
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
const int maxn=56;
int match[maxn];
int dis[maxn][maxn];
bool vis[maxn];
//int haha[maxn][maxn];
int stay[maxn],gohome[maxn];
int n;
int T;
int path(int u)
{
for(int v=1;v<=n;v++)
{
if(dis[u][v]&&!vis[v])
{
vis[v]=1;
if( match[v]==-1 || path( match[v] ))
{
//match[u]=v;
match[v]=u;
return 1;
}
}
}
return 0;
}
void hungary()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&stay[i]);
if(stay[i]!=1&&stay[i]!=0)stay[i]=0;
match[i]=-1;
}
for(int i=1;i<=n;i++)
{
scanf("%d",&gohome[i]);
if(gohome[i]!=1&&gohome[i]!=0)gohome[i]=0;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
scanf("%d",&dis[i][j]);
if(dis[i][j]!=1&&dis[i][j]!=0)dis[i][j]=0;
if(i==j)dis[i][j]=1;
if(stay[j]==0)
{
dis[i][j]=0;
}
}
}
for(int i=1;i<=n;i++)
{
if(stay[i]==0||(stay[i]==1&&gohome[i]==0))
{
memset(vis,0,sizeof(vis));
if(!path(i))
{
printf("T_T\n");
return;
}
}
}
printf("^_^\n");
}
void iCleaner()
{
//memset(match,-1,sizeof(match));
memset(vis,0,sizeof(vis));
memset(dis,0,sizeof(dis));
}
int imain()
{
freopen("zjoi09holiday.in","r",stdin);
freopen("zjoi09holiday.out","w",stdout);
scanf("%d",&T);
while(T--)
{
iCleaner();
hungary();
}
// while(1);
return 0;
}
int ishubang=imain();
int main()
{
;
}