有为杯  Problem I

DAG  有向无环图

A direct acylic graph(DAG),is a directed graph with no directed cycles . That is ,it is formed by a collection of  vertion  of  vertices  and  directed  edges ,  each     edge

connecting   one vertex to another,such that there is no way to way start at some vertex   v  and follow a squence of edges  that eventually  loops  back to v  again.

Given  a  DAG,output how many vertices each vetex can reach (including itself).

这是我根据题目写的算法,请各位品评、品评

#include<iostream>
#define g  10000
using namespace std;
int istr[g];//遍历过的点做标志
int a[g][g];

//深度遍历
void deeptaG(int k,int n){ 
int i;
istr[n]=1;
 for(i=0;i<k;i++){
  if(a[n][i]!=0 && !istr[i]){
  deeptaG(k,i);
  }
 }
}

int main(){

int o,p,i,k,j;
 int n,l;
 cin>>k>>l;
 while(l--){
 cin>>o>>p;
 a[o][p]=1;}

for (i=0;i<k;i++){
  for (int h=0;h<k;h++)
  { istr[h]=0; }
 deeptaG(k,i);
 j=0;
 for(int u=0;u<k;u++)
 if(istr[u]==1){++j;}
cout<<j<<endl;
 }
return  0;
}

2013年 ACM 有为杯 Problem I (DAG)的更多相关文章

  1. [2013山东ACM]省赛 The number of steps (可能DP,数学期望)

    The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

  2. 2013 gzhu acm

    题目描述: Word Counting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Other ...

  3. ACM - a + b Problem

    前几天看了ACM的第一题,映入眼帘的是一个“简单”的题目: 输入两个数,a,b 输出他们的和. 本着,此乃ACM的原则,便有了如下的思考: ACM的题目肯定很难,a+b,怎么可能直接printf,不行 ...

  4. ACM: A Simple Problem with Integers 解题报告-线段树

    A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...

  5. 2013年ACM湖南省赛总结

    今年的比赛最大的变化就是改用OJ判题了,相比于PC^2确实省事了不少,至少可以直接复制样例了.题目方面依旧是刘汝佳命题,这点还是相当好的,至少给人以足够的安全感. 开始比赛之后安叔瞬间就把前半部分题目 ...

  6. ACM——A + B Problem (4)

    A + B Problem (4) 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:2496            测试通过:124 ...

  7. ACM——A + B Problem (3)

    Home Problems 1086 A + B Problem (3) 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:2317 ...

  8. ACM——A + B Problem (2)

    A + B Problem (2) 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:2600            测试通过:137 ...

  9. ACM——A + B Problem (1)

    A + B Problem (1) 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:5907            测试通过:151 ...

随机推荐

  1. JavaMail回复

    JavaMail邮件回复 http://blog.csdn.net/o_darling/article/details/17558049 http://blog.csdn.net/xiyang_199 ...

  2. 实现拦截API的钩子(Hook)

    道理不多讲,简单说就是将系统API的跳转地址,替换为我们自己写的API的地址,所以要求我们自定义的API函数要和被拦截的API有相同的参数.在用完后,记得恢复. 因为要挂全局的钩子,所以Hook的部分 ...

  3. overload的一点思考

    仅参数类型不同的重载方法,使用过程的一个困惑: 有没有必要使用instanceof方法? package overload.special; public class OverLoadTest { p ...

  4. c# xml操作类

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xm ...

  5. jQuery背景跟随鼠标移动的网页导航

    首页 PSD模板 CSS模板 特效插件 源码下载 酷站欣赏 建站资源 建站教程 心境之旅 在线留言 设为首页 加入收藏 我要投稿 联系站长 Search     首页 PSD模板 CSS模板 特效插件 ...

  6. POJ 1182 食物链(并查集拆点)

    [题目链接] http://poj.org/problem?id=1182 [题目大意] 草原上有三种物种,分别为A,B,C A吃B,B吃C,C吃A. 1 x y表示x和y是同类,2 x y表示x吃y ...

  7. visibleViewController和topViewController 获取当前显示的页面

    原文:http://blog.sina.com.cn/s/blog_881ed8500102vo38.html UINavigationController 中有visibleViewControll ...

  8. 最大流算法----(SAP 和 EK)

    EK算法的核心 反复寻找源点 s 到汇点 t 之间的增广路径,若有,找出增广路径上每一段的最小值delta,若无,则结束. 寻找增广路径时用BFS来找,并且更新残留网的值. 找到delta后,则使最大 ...

  9. Linux 学习之防火墙配置

    1.安装iptables防火墙 yum install iptables  2. 清除已有的iptables规则  iptables -F  iptables -X  iptables -Z  3.显 ...

  10. HTML5兼容IE各版本的写法

    IE下判断IE版本的语句 <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见   <!--[if lte IE 7]> < ...