POJ 3256 DFS水题
枚举点 每次都搜一遍
//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 20005
int ans,k,n,m,first[N],next[N],v[N],tot,xx,yy,mark[N],vis[1005];
void add(int x,int y){
v[tot]=y,next[tot]=first[x],first[x]=tot++;
}
void dfs(int x){
for(int i=first[x];~i;i=next[i])
if(!vis[v[i]])
vis[v[i]]=1,dfs(v[i]);
}
int main(){
memset(first,-1,sizeof(first));
scanf("%d%d%d",&k,&n,&m);
for(int i=1;i<=k;i++)scanf("%d",&mark[i]);
for(int i=1;i<=m;i++)
scanf("%d%d",&xx,&yy),add(yy,xx);
for(int i=1;i<=n;i++){
vis[i]=1,dfs(i);
for(int j=1;j<=k;j++){
if(!vis[mark[j]])break;
if(j==k)ans++;
}
memset(vis,0,sizeof(vis));
}
printf("%d\n",ans);
}
POJ 3256 DFS水题的更多相关文章
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
- 【wikioi】1229 数字游戏(dfs+水题)
http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...
- DFS水题 URAL 1152 False Mirrors
题目传送门 /* 题意:一个圈,每个点有怪兽,每一次射击能消灭它左右和自己,剩余的每只怪兽攻击 搜索水题:sum记录剩余的攻击总和,tot记录承受的伤害,当伤害超过ans时,结束,算是剪枝吧 回溯写挫 ...
- poj 3264 RMQ 水题
题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...
- Poj 1552 Doubles(水题)
一.Description As part of an arithmetic competency program, your students will be given randomly gene ...
- 咸鱼的ACM之路:DFS水题集
DFS的核心就是从一种状态出发,转向任意的一个可行状态,直到达到结束条件为止.(个人理解) 下面全是洛谷题,毕竟能找到测试点数据的OJ我就找到这一个....在其他OJ上直接各种玄学问题... P159 ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- Oil Deposits(poj 1526 DFS入门题)
http://poj.org/problem?id=1562 ...
随机推荐
- libcudnn (R5) not found in library path
环境:Ubuntu 18.04 + Torch7 + cuda10 在运行使用cudnn的lua程序的时候产生错误: /home/majiabiao/torch/: /home/majiabiao/ ...
- 学习参考《父与子的编程之旅python【第二版】》高清中文版PDF+高清英文版PDF+源代码
对于初步接触编程语言的朋友,推荐看一看<父与子的编程之旅第2版>,对于完全编程零基础的很友好! 图文并茂,过多的文字堆垒很容易让人产生厌倦情绪,也更容易让人产生放弃的想法.使用了大量插图, ...
- 紫书 习题 8-16 UVa 1618 (中途相遇法)
暴力n的四次方, 然而可以用中途相遇法的思想, 分左边两个数和右边两个数来判断, 最后合起来判断. 一边是n平方logn, 合起来是n平方logn(枚举n平方, 二分logn) (1)两种比较方式是相 ...
- 洛谷P4994 终于结束的起点
希望是这道题的第一篇题解,并且真的做到了! upd 2018/11/4:规律补锅,让代码更加易懂 本来月赛时想打个表,打到一半,发现\(n\)稳定在\(m\)附近? 题目的意思是\(n < m ...
- Mysql锁表
lock tables是线程锁定表 lock tables table_name read lock tables table_name write read表示 所有用户只能读取被锁的表,不能对其进 ...
- Why functions - Not only for python
It may not be clear why it is worth the trouble to divide a program into functions. There are a lot ...
- jsp输出当前时间
在jsp页面中输出完整的时间,格式为"年 月 日 时:分:秒" <% Date date = new Date(); SimpleDateFormat t = new Si ...
- Git放弃本地更改恢复到资源库版本
使用git版本控制工具在本地clone一份代码后,如果发现修改错误想恢复到资源库版本,下面两行可以轻松加愉快的搞定: git clean -xdf git checkout -f git的更多详细用法 ...
- bootstrap-treeview简单使用
废话不多说,直接上干干货. 1.bootstrap-treeview Github网址:https://github.com/jonmiles/bootstrap-treeview 2.使用要求: & ...
- javascript ---(常用工具类的封装)
1. type 类型判断 isString(o) { //是否字符串 return Object.prototype.toString.call(o).slice(8, -1) === 'String ...