枚举点 每次都搜一遍

//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. 如何绑定host

    绑定host一般分为windows和linux下两种情况. windows下,首先打开host文件,其操作步骤 ,打开 C:\Windows\System32\Drivers\etc\hosts的文件 ...

  2. Javascript系列——对象元素的数组去重实现

    概要 这是一篇记录文,记录数组操作对象去重的实现. 需求 有这样一个数组 [{ _id: 123, name: '张三' },{ _id: 124, name: '李四' },{ _id: 123, ...

  3. Eclipse配置class文件输出目录

    1, Eclipse选中项目名称,邮件选中“Build Path”,然后选择“Configure Build Path”--->选择“Source” Tab---->修改"Def ...

  4. Mysql学习总结(28)——MySQL建表规范与常见问题

    一. 表设计 库名.表名.字段名必须使用小写字母,"_"分割. 库名.表名.字段名必须不超过12个字符. 库名.表名.字段名见名知意,建议使用名词而不是动词. 建议使用InnoDB ...

  5. how to deal with &quot;no such file error or diretory&quot; error for a new programmer in QT creator

    when i try to develop a hello demo in QT creator with the code following : #include<QApplication& ...

  6. leetcode 刷题之路 66 Path Sum II

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

  7. 12、NIO、AIO、BIO一

    1.NIO概述 什么是NIO:NIO是New I/O的简称,与旧式的基于流的I/O方式相对,从名字看,他表示新的一套JAVA I/O标准.它是在java1.4中被纳入到JDK中的,并具有以下特性: - ...

  8. invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause

    Column 'dbo.tbm_vie_View.ViewID' is invalid in the select list because it is not contained in either ...

  9. rest_framework 视图

    视图: a.过去 class PagerView(View): pass b.现在 class Pager1View(APIView): pass c.rest_framework 基本没用 from ...

  10. HDU4825:Xor Sum 解题报告(0/1 Trie树)

    Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数. 随后 Prometheus 将向 Ze ...