# (二分图匹配) bzoj 1433

## 1433: [ZJOI2009]假期的宿舍

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1451  Solved: 628
[Submit][Status][Discuss]

1
3
1 1 0
0 1 0
0 1 1
1 0 0
1 0 0

ˆ ˆ

## Source

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> e[205];
int judge[205],go[205],mp[205][205],lnk[205],mark[205];
int n;
bool dfs(int x)
{
for(int i=0;i<e[x].size();i++)
{
int v=e[x][i];
if(mark[v]==-1)
{
mark[v]=1;
if(lnk[v]==-1||dfs(lnk[v]))
{
lnk[v]=x;
return true;
}
}
}
return false;
}
int main()
{
int tt;
scanf("%d",&tt);
while(tt--)
{
memset(lnk,-1,sizeof(lnk));
memset(mp,0,sizeof(mp));
scanf("%d",&n);
for(int i=1;i<=n;i++)
e[i].clear();
for(int i=1;i<=n;i++)
scanf("%d",&judge[i]);
for(int i=1;i<=n;i++)
scanf("%d",&go[i]);
for(int i=1;i<=n;i++)
{
if(judge[i]&&!go[i])
{
e[i].push_back(i+n);
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
scanf("%d",&mp[i][j]);
if(!judge[i]||(judge[i]&&!go[i]))
{
for(int j=1;j<=n;j++)
{
if(mp[i][j]&&judge[j])
e[i].push_back(j+n);
}
}
}
bool flag=true;
for(int i=1;i<=n;i++)
{
if(!judge[i]||(judge[i]&&!go[i]))
{
memset(mark,-1,sizeof(mark));
if(!dfs(i))
{
flag=false;
break;
}
}
}
if(flag)
printf("^_^\n");
else
printf("T_T\n");
}
return 0;
}


posted @ 2015-05-20 09:12  waterfull  阅读(112)  评论(0编辑  收藏  举报