枚举点 每次都搜一遍

//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. LINUX 中 python 版本升级

    首先下载源tar包 可利用linux自带下载工具wget下载,如下所示: 1 # wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tg ...

  2. Informatica环境搭建过程中一些问题-近期项目进了新人,在搭建环境中存在一些问题,之前都处理过一直没有整理,这次接着机会,把这些常见问题处理整理出来

    一.Informatica9.5.1创建资源库出错找不到libpmora8.so 错误如下: Database driver event...Error occurred loading librar ...

  3. How to customize Skin Gallery - Remove / rename skins and groups

    1. REMOVE (HIDE) A SPECIFIC SKIN Traverse through the gallery group collection, then through its gal ...

  4. hdu 1166 敌兵布阵 (线段树单点更新)

    敌兵布阵                                                         Time Limit: 2000/1000 MS (Java/Others)  ...

  5. Unity渲染

    我们先大概了解一下对渲染的优先级有影响的几个因素 1.Camera.Depth 不同相机的深度,在渲染顺序的优先度里面是最高的,Depth越大,渲染的图像越靠前 2.Render.SortingOrd ...

  6. 转:iPhone libxml2 not found during build

    在新建的一个项目中,出现编译错误,发现是缺少了libxml2.dylib,后面将这个资源包添加了,编译还是出现标题上所说的问题 #import <libxml/tree.h> //#imp ...

  7. 【LeetCode-面试算法经典-Java实现】【064-Minimum Path Sum(最小路径和)】

    [064-Minimum Path Sum(最小路径和)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a m x n grid filled with ...

  8. word 的使用 —— 分页符与分节符

    节的概念:节定义了一些格式, 如页边距.页面的方向.页眉和页脚,以及页码的顺序. 分节符是指为表示节的结尾插入的标记. 分节符的作用: 分节符起着分隔其前后文本格式的作用,如果删除了某个分节符,它前面 ...

  9. Mysql-in查询问题

    Mysql-in查询问题 标签(空格分隔): mysql 问题:mysql用in语法查询出来的数据少了好多! 我的实际情况: 数据表: content字段记录着一些选项的id,多个选项用逗号隔开,比如 ...

  10. Nginx下部署TP5项目

    标签(空格分隔): linux nginx配置文件: server { listen 81; #listen [::]:80; server_name _; index index.html inde ...