枚举点 每次都搜一遍

//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水题的更多相关文章

  1. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  2. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  3. 【wikioi】1229 数字游戏(dfs+水题)

    http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...

  4. DFS水题 URAL 1152 False Mirrors

    题目传送门 /* 题意:一个圈,每个点有怪兽,每一次射击能消灭它左右和自己,剩余的每只怪兽攻击 搜索水题:sum记录剩余的攻击总和,tot记录承受的伤害,当伤害超过ans时,结束,算是剪枝吧 回溯写挫 ...

  5. poj 3264 RMQ 水题

    题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  6. Poj 1552 Doubles(水题)

    一.Description As part of an arithmetic competency program, your students will be given randomly gene ...

  7. 咸鱼的ACM之路:DFS水题集

    DFS的核心就是从一种状态出发,转向任意的一个可行状态,直到达到结束条件为止.(个人理解) 下面全是洛谷题,毕竟能找到测试点数据的OJ我就找到这一个....在其他OJ上直接各种玄学问题... P159 ...

  8. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  9. Oil Deposits(poj 1526 DFS入门题)

    http://poj.org/problem?id=1562                                                                       ...

随机推荐

  1. 关于__str__的介绍

    在python语言里,__str__一般是格式是这样的. class A: def __str__(self): return "this is in str" 事实上,__str ...

  2. 大O时间复杂度

    大O表示法指出了在最糟情况下的运行时间.比较操作数,指出了算法运行时间的增速 常见的大O运行时间 O(logn):也叫对数时间,包括二分查找 O(n):也叫线性时间,包括简单查找 O(nlogn):包 ...

  3. 总结使人进步,可视化界面GUI应用开发总结:Android、iOS、Web、Swing、Windows开发等

    可视化界面的软件,是21世纪最主流的应用类型了,黑屏控制台的不适合普通用户.   2004年左右的时候,作为普通网民,接触的自然是可视化,准确是Windows那一套.   那个时候,Microsoft ...

  4. 【BZOJ 1193】 [HNOI2006]马步距离

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 原问题可以等价为两个点. 然后其中一个点要移动到另外一个点. 那么我们可以把左下角那个点(对称总是可以得到一个点在左下角)放在原点的 ...

  5. Effective JavaScript Item 49 对于数组遍历,优先使用for循环,而不是for..in循环

    本系列作为Effective JavaScript的读书笔记. 对于以下这段代码,能看出最后的平均数是多少吗? var scores = [98, 74, 85, 77, 93, 100, 89]; ...

  6. Canvas中的非零围绕规则原理

    非零围绕规则:对于路径中指定范围区域,从该区域内部画一条足够长的线段.使此线段的全然落在路径范围之外. 非零围绕规则计数器:然后,将计数器初始化为0,每当这个线段与路径上的直线或曲线相交时,就改变计数 ...

  7. Android jni 二维数组 传递

    学习Android Jni时,一个二维 整数 数组的传递花了我好长时间,在网上查的资料都不全,当然最后是成功了,写在这里是为了自己记住,当然有人搜索到并利用了我会很高兴.   in Android J ...

  8. pyspark.mllib.feature module

    Feature Extraction Feature Extraction converts vague features in the raw data into concrete numbers ...

  9. poj--1789--Truck History(prim)

    Truck History Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit ...

  10. cnmp安装失败,报错npm ERR! enoent ENOENT: no such file or directory,

    1.cnmp安装失败 2.提示如下: bogon:node_modules liangjingming$ sudo npm install cnpm -g --registry=https://reg ...