bzoj1648[usaco2006 Dec]cow Picnic Cow Picnic
Test instructions
K cows scatter in n pastures and ask how many places are available to all cows. n≤1000
Exercises
Inverted into side and then on each point DFS, if the cows passed by the K then accumulate the answer. Note that there may be more than one cow in the same ranch, with an array of records.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #defineMAXN 10106 using namespacestd;7 8InlineintRead () {9 CharCh=getchar ();intf=1, x=0;Ten while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A returnf*x; - } - structe{intT,n;}; E es[maxn*Ten];intg[maxn],ess; the voidPeintFintT) {es[++ess]= (e) {t,g[f]}; g[f]=ess;} - BOOLCOW[MAXN],VIS[MAXN];intans,tot,k,n,m,cnt; - voidDfsintx) { - if(Cow[x]) tot++; for(intI=G[X];I;I=ES[I].N)if(!vis[es[i].t]) vis[es[i].t]=1, DFS (es[i].t); + } - intMain () { +K=read (), N=read (), m=read (); AInc (I,1, k) {intA=read (); cow[a]=1;} Inc (I,1, m) {intA=read (), b=read (); PE (B,A);} atk=0; Inc (I,1, N)if(Cow[i]) k++; -Inc (I,1, N) { -memset (Vis,0,sizeof(VIS)); vis[i]=1; tot=0; DFS (i);if(tot==k) ans++; - } -printf"%d", ans);return 0; -}
20160810
bzoj1648[usaco2006 Dec]cow Picnic Cow Picnic *