bzoj1648[usaco2006 Dec]cow Picnic Cow Picnic *

Source: Internet
Author: User

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 *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.