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

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 3265  Solved: 1369
[Submit][Status][Discuss]

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

ˆ ˆ

## Source

QAQ 改了老半天才知道格式错了

#include <cstring>
#include <cstdio>
#include <queue>
#define N 50000
using namespace std;
inline void init()
{
cnt=1;
ans=0;
memset(nextt,0,sizeof(nextt));
}
inline void ins(int u,int v,int w)
{
to[cnt]=v;
flow[cnt]=w;
}
bool bfs(int S,int T)
{
for(int i=S;i<=T;++i) dep[i]=-1;
queue<int>q;
dep[S]=0;
q.push(S);
for(int now;!q.empty();)
{
now=q.front();q.pop();
{
int v=to[i];
if(dep[v]==-1&&flow[i])
{
dep[v]=dep[now]+1;
if(v==T) return true;
q.push(v);
}
}
}
return false;
}
int dfs(int now,int T,int Limit)
{
if(now==T||!Limit) return Limit;
int ret=0,f;
{
int v=to[i];
if(dep[v]==dep[now]+1&&flow[i]&&(f=dfs(v,T,min(Limit,flow[i]))))
{
ret+=f;
Limit-=f;
flow[i]-=f;
flow[i^1]+=f;
if(!Limit) break;
}
}
if(ret!=Limit) dep[now]=-1;
return ret;
}
int Dinic(int S,int T)
{
for(;bfs(S,T);ans-=dfs(S,T,0x3f3f3f3f));
return ans;
}
int Main()
{
scanf("%d",&T);
for(int n,x;T--;)
{
init();
scanf("%d",&n);
int S=0,T=n*n+1;
for(int i=1;i<=n;++i)
{
scanf("%d",&zx[i]);
if(zx[i]) ins(i+n,T,1),ins(T,i+n,0);
}
for(int i=1;i<=n;++i)
{
scanf("%d",&x);
if((!x&&zx[i])||!zx[i]) ins(S,i,1),ins(i,S,0),ans++;
}
for(int i=1;i<=n;++i)
{
if(zx[i]) ins(i,i+n,1),ins(i+n,i,0);
for(int j=1;j<=n;++j)
{
scanf("%d",&x);
if(x) ins(i,j+n,1),ins(j+n,i,0);
}
}
if(Dinic(S,T)==0) printf("%c%c%c\n",94,95,94);
else printf("%c%c%c\n",84,95,84);
}
return 0;
}
int sb=Main();
int main(int argc,char *argv[]){;}

posted @ 2017-09-29 11:06  杀猪状元  阅读(94)  评论(0编辑  收藏  举报