1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
2017-07-16 19:30
281 查看
题目链接
题目大意:求有向图中所有点可达的点的个数
题解:搜
我的收获:……
题目大意:求有向图中所有点可达的点的个数
题解:搜
我的收获:……
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int M=1005; int n,m,x,y,z,t,k,tot; int vis[M],head[M],cow[M],mark[M]; struct edge{ int to,next; }e[M*10]; void add(int i,int j) { e[t].to=j; e[t].next=head[i]; head[i]=t++; } void init() { memset(head,-1,sizeof(head)); scanf("%d%d%d",&k,&n,&m); for(int i=1;i<=k;i++) scanf("%d",&cow[i]); while(m--) { scanf("%d%d",&x,&y); add(x,y); } } void dfs(int u) { vis[u]=1;mark[u]++; for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; if(!vis[v]) dfs(v); } } void work() { for(int i=1;i<=n;i++){ memset(vis,0,sizeof(vis)); dfs(cow[i]); } for(int i=1;i<=n;i++) if(mark[i]==k) tot++; printf("%d\n",tot); } int main() { init(); work(); return 0; }
相关文章推荐
- Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset
- bzoj1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 题解
- bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐(暴力DFS)
- 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- [BZOJ] 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- bzoj1648 [Usaco2006 Dec]Cow Picnic 奶牛野餐
- bzoj1648 [Usaco2006 Dec]Cow Picnic 奶牛野餐
- |BZOJ 1648|DFS|[Usaco2006 Dec]Cow Picnic 奶牛野餐
- bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐【dfs】
- 【BZOJ】1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐(dfs)
- BZOJ 1648 USACO 2006 Dec Cow Picnic 奶牛野餐 搜索
- bzoj1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- bzoj1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 (搜索+剪枝)
- bzoj1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- 【Usaco】2006 Dec - Cow Picnic
- BZOJ1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 后缀数组