2013年 ACM 有为杯 Problem I (DAG)
有为杯 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)的更多相关文章
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...
- 2013 gzhu acm
题目描述: Word Counting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Other ...
- ACM - a + b Problem
前几天看了ACM的第一题,映入眼帘的是一个“简单”的题目: 输入两个数,a,b 输出他们的和. 本着,此乃ACM的原则,便有了如下的思考: ACM的题目肯定很难,a+b,怎么可能直接printf,不行 ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- 2013年ACM湖南省赛总结
今年的比赛最大的变化就是改用OJ判题了,相比于PC^2确实省事了不少,至少可以直接复制样例了.题目方面依旧是刘汝佳命题,这点还是相当好的,至少给人以足够的安全感. 开始比赛之后安叔瞬间就把前半部分题目 ...
- ACM——A + B Problem (4)
A + B Problem (4) 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:2496 测试通过:124 ...
- ACM——A + B Problem (3)
Home Problems 1086 A + B Problem (3) 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:2317 ...
- ACM——A + B Problem (2)
A + B Problem (2) 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:2600 测试通过:137 ...
- ACM——A + B Problem (1)
A + B Problem (1) 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:5907 测试通过:151 ...
随机推荐
- Oracle EBS-SQL (INV-3):检查仓库库存价值明细.sql
SELECT a.subinventory_code 子库代码 ,d.DESCRIPTION ...
- 使用plist的好处
首先:帮助节省内存.OpenGL ES纹理要求宽和高都是2的n次幂的倍数.我们可以考虑将小的图片拼大图片,然后统一加载. 其次:提高渲染速度.OpenGL ES要求切换的纹理越少越好,将图片拼成大图 ...
- 关于“创业者与VC见面的10个不成文细节点”
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:Will Wang链接:http://www.zhihu.com/question/19641135/answer/50974 ...
- Mobile Service更新和 Notification Hub 对Android的支持
本周,我们要推出一些更新,使移动服务成为移动应用程序更强大.更灵活的后端,同时推出一个与移动服务或网站结合使用的免费 20MB SQL 数据库,并且将支持通过Notification Hub中的 GC ...
- floodlight 学习(一)
其实这个控制器应该没有多少人用了吧,一年多都没更新了,鉴于最近无论如何都要用这个,将学习笔记贴出来吧. 1.FloodlightProvider(Dev) 1.1简介:FloodlightProvid ...
- C++ STL 一般总结
以下内容来源网上 经过整合而成(转载) 一.一般介绍 STL(Standard Template Library),即标准模板库,是一个具有工业强度的,高效的C++程序库.它被容纳于C++标准程序库( ...
- HDOJ 2689
Sort it Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- C# foreach获取集合元素索引的坑
,}; foreach(var prepareId in prepareIds) { Console.WriteLine(prepareIds.IndexOf(prepareId)); } 执行结果如 ...
- .net通用权限框架B/S (四)--DAL数据层以及数据接口
数据层以及数据接口设计如下图(以g_orga组织机构和g_role角色)为例,这几个类可以通过.tt模版生成 设计参考学习http://www.cnblogs.com/hanyinglong/arch ...
- left join 和 left outer join 的区别
left join 和 left outer join 的区别 通俗的讲: A left join B 的连接的记录数与A表的记录数同 A right join ...