//题意是 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. Unity中自定义扩展方法

    问题背景 在使用unity开发过程中,通常会遇到一种情况,比如说给物体重新赋值坐标的问题, Transfrom tran: ,pos_y=,pos_z=; tran.position=new Vect ...

  2. MVC学习九:MVC 特性本质

    一.特性的本质就是:对属性.方法.类加特性,本质就是new 一个特性类对象赋值给属性.方法.类. 可以通过反射的方式取得特性的值,代码如下: ①自定义特性 public class MyAttribu ...

  3. mysql的入门基本使用(适合新手学习)

    登陆Mysql数据库mysql -u root -p 展示(查询)所有数据库show databases;进入数据库use dataname;创建数据库create database dataname ...

  4. android中OpenMax的实现【2】AwesomePlayer中openmax的入口

    AwesomePlayer 中有个变量 OMXClient mClient; 让我们看看   OMXClient class OMXClient { public: OMXClient(); stat ...

  5. JS获取MVC Attrbuate验证是否通用

    直接用JQValidate的方法,$("#FeedBackForm").valid(); 当结果是true表示验证通过,false时表示验证失败~

  6. NopCommerce 3.4中商品详情页面单选框、复选框的美化

    先上图给大家看看效果,点这里打开网站(后期可能会找不到这个商品,现在再测试阶段) 现在你能看到的这个页面中,尺寸.文本描述是单选框(属性是我乱写的名字),上门安装是复选框.效果就看到这里,请君跳过图片 ...

  7. Before start of result set

    ResultSet:在处理结果集的时候出现了问题. 解决办法:while(rs.next())

  8. GoBelieve IM 服务端编译

    #部署im1. 安装go编译环境参考链接:https://golang.org/doc/install 2. 下载im_service代码 cd $GOPATH/src/github.com/GoBe ...

  9. golang刷Leetcode系列 --- 实现strStr()

    实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始).如果不存在,则返 ...

  10. LogViewer超大文本浏览工具

    官方下载 LogViewer 是一款简单好用的log日志文件查看工具.您想要查看log日志吗?那么不妨来看看这款LogViewer .该款工具可以在短短数秒内打开上G的LOG文件,支持高亮某行文字(例 ...