//题意是 K N, M;

//有K个牛 N个牧场,M条路 ,有向的 

//把K个牛放到任意的n个不同牧场中,问所有牛都可以到达的牧场数的总和 

//这是一道简单的DFS题

//k 100

//n 1000

//m 10000

#include <iostream>

#include <cstdio>

#include <vector>

#include <cstring>

using namespace std;

int k, n, m;

int a[105];

int book[1005], sum[1005];

vector<int> map[1005];

void dfs( int x ) {
sum[x]++;
for(int i = 0;i<map[x].size();i++){
int  v = map[x][i];
if(book[v]==0){ 
book[v] = 1;
dfs(v);
}
}
return;

}

int main()

{

while(~scanf("%d%d%d",&k,&n,&m)){

for( int i = 1; i <= k ; i++ ) {
scanf("%d",&a[i]);
}

for(int i=1;i<=m;i++){
int a, b;
scanf("%d%d",&a,&b);
map[a].push_back(b);
}
memset(sum,0,sizeof(sum));
for(int i = 1;i <= k; i++ ) {
memset( book, 0, sizeof(book) );
book[a[i]] = 1;
dfs( a[i] );
}
int ans = 0;
for(int i=1;i<=n;i++){
if(sum[i]==k) ans++;

// cout<<" i = "<<i<<" sum [i] "<<sum[i]<<endl;

cout<<ans<<endl;
}

    return 0;

}

POJ 3256 (简单的DFS)的更多相关文章

  1. POJ 2243 简单搜索 (DFS BFS A*)

    题目大意:国际象棋给你一个起点和一个终点,按骑士的走法,从起点到终点的最少移动多少次. 求最少明显用bfs,下面给出三种搜索算法程序: // BFS #include<cstdio> #i ...

  2. POJ 1321 棋盘问题 --- DFS

    POJ 1321 题目大意:给定一棋盘,在其棋盘区域放置棋子,需保证每行每列都只有一颗棋子. (注意 .不可放 #可放) 解题思路:利用DFS,从第一行开始依次往下遍历,列是否已经放置棋子用一个数组标 ...

  3. 暴力求解——UVA 572(简单的dfs)

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  4. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  5. The Die Is Cast(poj 1481简单的双dfs)

    http://poj.org/problem?id=1481 The Die Is Cast Time Limit: 1000MS   Memory Limit: 10000K Total Submi ...

  6. POJ 1321 简单dfs

    1.POJ 1321  棋盘问题 2.总结: 题意:给定棋盘上放k个棋子,要求同行同列都不重. #include<iostream> #include<cstring> #in ...

  7. POJ 1321 棋盘问题(DFS板子题,简单搜索练习)

    棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44012   Accepted: 21375 Descriptio ...

  8. poj 1321 (简单DFS) 棋盘问题

    题目:http://poj.org/problem?id=1321 最近状态有点down, 练练手 #include<cstdio> using namespace std; ][]; ] ...

  9. poj 1426 Find The Multiple (简单搜索dfs)

    题目: Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal ...

随机推荐

  1. Spring 通过XML配置装配Bean

    使用XML装配Bean需要定义对于的XML,需要引入对应的XML模式(XSD)文件,这些文件会定义配置Spring Bean的一些元素,简单的配置如下: <?xml version=" ...

  2. PAT——不吉利的日期(java中date和Calendar使用)

    题目描述 在国外,每月的 13 号和每周的星期 5 都是不吉利的.特别是当 13 号那天恰好是星期 5时,更不吉利. 现在给你一个年份,请你从小到大依次输出当年所有13 号是星期 5 的月份. 输入描 ...

  3. C/C++判断文件/文件夹是否存在 转

    一.判断文件夹是否存在:     1.用CreateDirectory(".//FileManege",NULL);如果文件夹FileManege不存在,则创建.     2.或者 ...

  4. tensorflow节点布放(device assignment of node)算法:simpler_placer

    tensorflow v0.9中目前在用的devcie assignment算法是simple placer算法,相比于白皮书中cost model算法实现简单.simpler placer算法优先选 ...

  5. Gradle Goodness: Unpacking an Archive

    To create an archive with Gradle is easy. We have several tasks like Zip, Tar, Jar, War and Ear to c ...

  6. vue 方法相互调用注意事项与详解

    vue在同一个组件内: methods中的一个方法调用methods中的另外一个方法: 可以直接这样调用:this.$options.methods.test(); this.$options.met ...

  7. BZOJ 3771: Triple(生成函数 FFT)

    Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 911  Solved: 528[Submit][Status][Discuss] Description ...

  8. git创建使用1https://blog.csdn.net/Hanani_Jia/article/details/77950594

    这篇文章是我自己写的关于GitHub的内容,从我刚听到这个直到设置成功每一步都有详细的步骤来解释,其中有一些截图或者代码来自于网上. 首先,我先对GitHub来一个简单的介绍,GitHub有一个很强大 ...

  9. (转载)PHP环境搭建-记录

    PHP环境搭建-记录   转于 http://jingyan.baidu.com/article/fcb5aff797ec41edaa4a71c4.html php5.5 做了大量的更新,在与apac ...

  10. Java虚拟机(JVM)内存区域

            Java虚拟机内存区域分为五部分:程序计数器.Java虚拟机栈.本地方法栈.堆.方法区.其中程序计数器.Java虚拟机栈.本地方法栈属于线程私有内存区,其生命周期与线程相同,随线程的产 ...