Title Description
Transmission Door
Exercises
The people who live are all the people who don't go home and all the people who come to see XI, and some dorms are all students Yi.
s->xi,1 yi->t,1 for the IJ know, xi->yi,1
That is, the maximum match.
Code
#include <iostream>#include <cstring>#include <cstdio>#include <queue>using namespace STD;Const intmax_n= -;Const intmax_n=max_n*2+2;Const intMax_m=max_n*max_n;Const intmax_e=max_m*2;Const intinf=2e9;intT,n,n,a,b,maxflow;intSchool[max_n],home[max_n],known[max_n][max_n],a[max_n],b[max_n];intTOT,POINT[MAX_N],NXT[MAX_E],V[MAX_E],REMAIN[MAX_E];intDeep[max_n],cur[max_n]; Queue <int>Qinline voidClear () {maxflow=0;memset(School,0,sizeof(school));memset(Home,0,sizeof(home));memset(Known,0,sizeof(known));memsetA0,sizeof(a));memset(b,0,sizeof(b)); A=0; b=0; tot=-1;memset(point,-1,sizeof(point));memset(nxt,-1,sizeof(NXT));memset(V,0,sizeof(v));memset(Remain,0,sizeof(remain));memset(Deep,0,sizeof(deep));memset(cur,0,sizeof(cur));}inline voidAddedge (intXintYintCAP) {++tot; nxt[tot]=point[x]; point[x]=tot; v[tot]=y; remain[tot]=cap; ++tot; Nxt[tot]=point[y]; Point[y]=tot; V[tot]=x; remain[tot]=0;}inline BOOLBFsintSintT) {memset(Deep,0x7f,sizeof(deep)); deep[s]=0; for(intI=1; i<=n;++i) Cur[i]=point[i]; while(!q.empty ()) Q.pop (); Q.push (s); while(!q.empty ()) {intNow=q.front (); Q.pop (); for(inti=point[now];i!=-1; I=nxt[i])if(Deep[v[i]]>n&&remain[i]) {deep[v[i]]=deep[now]+1; Q.push (V[i]); } }returnDeep[t]<n;}inline intDfsintNowintTintLimit) {if(Now==t| |! LimitreturnLimitintf,flow=0; for(inti=cur[now];i!=-1; I=nxt[i])if(deep[v[i]]==deep[now]+1&& (F=dfs (V[i],t,min (remain[i],limit))) {flow+=f; Limit-=f; Remain[i]-=f; remain[i^1]+=f;if(!limit) Break; }returnFlow;}inline voidDinic (intSintT) { while(BFS (s,t)) Maxflow+=dfs (S,t,inf);}intMain () {scanf("%d", &t); while(t--) {Clear ();scanf("%d", &n); for(intI=1; i<=n;++i)scanf("%d", &school[i]); for(intI=1; i<=n;++i)scanf("%d", &home[i]); for(intI=1; i<=n;++i)if((School[i]&&!home[i]) | |! School[i]) a[++a]=i; for(intI=1; i<=n;++i)if(School[i]) b[++b]=i; for(intI=1; i<=n;++i) for(intj=1; j<=n;++j)scanf("%d", &known[i][j]); for(intI=1; i<=n;++i) known[i][i]=1; n=a+b+2; for(intI=1; i<=a;++i) Addedge (1,1+i,1); for(intI=1; i<=b;++i) Addedge (1+a+i,n,1); for(intI=1; i<=a;++i) for(intj=1; j<=b;++j)if(Known[a[i]][b[j]]) Addedge (1+i,1+a+j,1); Dinic (1, N);if(maxflow==a)printf("^_^ \ n");Else printf("t_t\n"); }}
[BZOJ1433] [ZJOI2009] Holiday dorm (Max Stream)