POJ 3256 (简单的DFS)
//题意是 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)的更多相关文章
- POJ 2243 简单搜索 (DFS BFS A*)
题目大意:国际象棋给你一个起点和一个终点,按骑士的走法,从起点到终点的最少移动多少次. 求最少明显用bfs,下面给出三种搜索算法程序: // BFS #include<cstdio> #i ...
- POJ 1321 棋盘问题 --- DFS
POJ 1321 题目大意:给定一棋盘,在其棋盘区域放置棋子,需保证每行每列都只有一颗棋子. (注意 .不可放 #可放) 解题思路:利用DFS,从第一行开始依次往下遍历,列是否已经放置棋子用一个数组标 ...
- 暴力求解——UVA 572(简单的dfs)
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
- 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 ...
- POJ 1321 简单dfs
1.POJ 1321 棋盘问题 2.总结: 题意:给定棋盘上放k个棋子,要求同行同列都不重. #include<iostream> #include<cstring> #in ...
- POJ 1321 棋盘问题(DFS板子题,简单搜索练习)
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44012 Accepted: 21375 Descriptio ...
- poj 1321 (简单DFS) 棋盘问题
题目:http://poj.org/problem?id=1321 最近状态有点down, 练练手 #include<cstdio> using namespace std; ][]; ] ...
- 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 ...
随机推荐
- Java 内部类综述
转载自:https://blog.csdn.net/justloveyou_/article/details/53245561
- HDU 2086 P - A1 = ?(推表达式)
传送门:http://acm.geekxiong.tech/vjudge/contest/view.action?cid=14#problem/P P - A1 = ? Time Limit:1000 ...
- indexPathForCell的事
UITableView *tableview = (UITableView *)self.superview; NSIndexPath *indexPath = [tableview indexPat ...
- iOS运用runtime全局修改UILabel的默认字体
iOS运用runtime全局修改UILabel的默认字体 一.需求背景介绍 在项目比较成熟的基础上,遇到了这样一个需求,应用中需要引入新的字体,需要更换所有Label的默认字体,但是同时,对于一些特殊 ...
- 《DOM编程艺术》读书笔记<概述>
作为一名前端开发工程师,学习的过程中总少不了各种各样的书籍,作为新手如何在众多书籍中选到适合自己的呢,我们今天先来谈谈<DOM编程艺术>这本书. 其实呢大部分书都是好书,就像LOL中大部分 ...
- 常见web漏洞
常见的web漏洞——文件上传漏洞 一.文件上传漏洞概述 文件上传漏洞是指用户上传了一个可执行的脚本文件,并通过此脚本文件获得了执行服务器端命令的能力.这种攻击方式是最为直接和有效的,有时候几乎没 ...
- hdu Hat's Fibonacci(用了kuangbin模板)
大数的位数设置很坑,设成700会越界,设成800会超空间,最后设成了750居然就过了.... #include <iostream> #include <cstdio> #in ...
- Cobbler实现自动化安装(上)--原理篇
了解Cobbler之前,我们需要先对PXE及KickStart有一定的认识. PXE PXE(Pre-bootExecution Environment),预启动执行环境,通过网络接口启动计算机,支持 ...
- Python模块、包、异常、文件(案例)
Python模块.包.异常.文件(案例) python.py #模块 # Python中的模块(Module),是一个Python文件,以.py文件结尾,包含了Python对象定义和Python语句, ...
- Web Services简单介绍
Web Services简单介绍 Web Services入门 一.Web Services简介 1.什么是Web Services? Web Services 是应用程序组件 Web Service ...