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 ...
随机推荐
- 常用在线工具及API网址总结
1.小图标在线查找 https://www.iconfinder.com/ 2.在线做图,Flowchart流程图,BPMN图,Org组织结构图等 http://www.processon.com/ ...
- android对应版本号
android对应版本号 Platform Version API Level VERSION_CODE Notes Android 4.2 JELLY_BEAN_MR1 Platform Highl ...
- Android studio gradle配置!!!【转】
转自:http://www.open-open.com/lib/view/open1415793464648.html Gradle 基本概念 首先我们学习几个gradle 的脚本语法,掌握了这几个语 ...
- 标头“Vary:Accept-Encoding”指定方法及其重要性分析
原文地址:http://www.webkaka.com/blog/archives/how-to-set-Vary-Accept-Encoding-header.html 在webkaka的网站速度诊 ...
- 习题3.15 自调整表Find例程
#include<stdio.h> #include<stdlib.h> typedef int * List; /* 自调整表的Find数组实现 */ int Find(Li ...
- process有个env属性,env属性就是环境变量,里面可以访问到NODE_ENV;NODE_ENV是在启动nodejs时添加上去的;
添加命令 为export NODE_ENV=production:
- How to use pagination in Magento
classYour_Module_Block_Entityname_ListextendsMage_Core_Block_Template { protected function _construc ...
- js正则验证两位小数 验证数字最简单正则表达式大全
<h3>输入完按回车后即可验证!(自认为最简单!)</h3> 正整数: <input type="text" size="20&quo ...
- POJ 2774 Long Long Message&&HDU 1403 Longest Common Substring&&COJ 1203
后缀数组的买1送2题... HDU的那题数据实在是太水了,后来才发现在COJ和POJ上都是WA..原因在一点:在建立sa数组的时候里面的n应该是字符串长度+1....不懂可以去看罗大神的论文... 就 ...
- D3学习教程
[ D3.js 入门系列 ] 入门总结 | OUR D3.JS http://www.ourd3js.com/wordpress/?p=396