从每个奶牛所在草场dfs,把沿途dfs到的草场的con都+1,最后符合条件的草场就是con==k的,扫一遍统计一下即可

#include<iostream>
#include<cstdio>
using namespace std;
const int K=105,N=1005;
int k,n,m,p[K],h[N],cnt,c[N],v[N],ti,ans;
struct qwe
{
int ne,to;
}e[N*10];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void add(int u,int v)
{
cnt++;
e[cnt].ne=h[u];
e[cnt].to=v;
h[u]=cnt;
}
void dfs(int u)
{
v[u]=ti,c[u]++;
for(int i=h[u];i;i=e[i].ne)
if(v[e[i].to]!=ti)
dfs(e[i].to);
}
int main()
{
k=read(),n=read(),m=read();
for(int i=1;i<=k;i++)
p[i]=read();
for(int i=1;i<=m;i++)
{
int x=read(),y=read();
add(x,y);
}
for(int i=1;i<=k;i++)
ti++,dfs(p[i]);
for(int i=1;i<=n;i++)
if(c[i]==k)
ans++;
printf("%d\n",ans);
return 0;
}

bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐【dfs】的更多相关文章

  1. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )

    直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...

  2. Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 346[ ...

  3. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐

    Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is graz ...

  4. 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 432  Solved: 270[ ...

  5. 【BZOJ】1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐(dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1648 水题.. dfs记录能到达的就行了.. #include <cstdio> #in ...

  6. bzoj1648 [Usaco2006 Dec]Cow Picnic 奶牛野餐

    Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is graz ...

  7. BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )

    有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...

  8. BZOJ——1649: [Usaco2006 Dec]Cow Roller Coaster

    http://www.lydsy.com/JudgeOnline/problem.php?id=1649 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 7 ...

  9. bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster【dp】

    DAG上的dp 因为本身升序就是拓扑序,所以建出图来直接从1到ndp即可,设f[i][j]为到i花费了j #include<iostream> #include<cstdio> ...

随机推荐

  1. HDU-1083Courses,二分图模板题!

    Courses                                                                                             ...

  2. spark streaming 踩过的那些坑

      系统背景 spark streaming + Kafka高级API receiver 目前资源分配(现在系统比较稳定的资源分配),独立集群 --driver-memory 50G   --exec ...

  3. Codeforces 777E(离散化+dp+树状数组或线段树维护最大值)

    E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. SQL Server Management Studio自定义快捷键

    SQL Server Management Studio支持自定义快捷键:工具->选项->键盘: 其中,Alt+F1.Ctrl+1.Ctrl+2是系统预定义的快捷键. 双击表名(或按Ctr ...

  5. [bzoj5379]Tree_dfs序_线段树_倍增lca

    Tree bzoj-5379 题目大意:给定一棵$n$节点的树.支持:换根.把节点$u$和$v$的$lca$的子树加.询问$u$的子树和. 注释:$1\le n,q\le 3\times 10^5$. ...

  6. yarn-cli 缓存

    yarn cache list Yarn 会在你的用户目录下开辟一块全局缓存用以保存下载的包.yarn cache list 用于列出所有已经缓存的包. yarn cache dir 执行 yarn ...

  7. Linux下完美使用find+grep实现全局代码搜索

    作者:zhanhailiang 日期:2014-10-11 背景 在Window下有大量方便的图形化工具能够实现全局搜索,可是Linuxserver中因为使用命令行操作导致全局搜索是一个比較高的门槛. ...

  8. C#高级编程五十四天----Lookup类和有序字典

    Lookup类 Dictionary<Tkey,TValue>仅仅为每一个键支持一个值.新类Lookup<Tkey,TValue>是.NET3.5中新增的,它类似与Dictio ...

  9. A program to print Fahrenheit-Celsius table with floating-point values

    我的主力博客:半亩方塘 Another program to print Fahrenheit-Celsius table with decimal integer This program is p ...

  10. FFmpeg将多张图片合成视频 子视频合并

    FFmpeg将多张图片合成视频 - CSDN博客 https://blog.csdn.net/wangshuainan/article/details/77914508 Slideshow – FFm ...