暑假集训(2)第一弹 -----Is It A Tree?(Poj308)
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu
Description
There is exactly one node, called the root, to which no directed edges point.
Every node except the root has exactly one edge pointing to it.
There is a unique sequence of directed edges from the root to each node.
For example, consider the illustrations below, in which nodes are represented by circles and edges are represented by lines with arrowheads. The first two of these are trees, but the last is not.
In this problem you will be given several descriptions of collections of nodes connected by directed edges. For each of these you are to determine if the collection satisfies the definition of a tree or not.
Input
Output
Sample Input
6 8 5 3 5 2 6 4
5 6 0 0 8 1 7 3 6 2 8 9 7 5
7 4 7 8 7 6 0 0 3 8 6 8 6 4
5 3 5 6 5 2 0 0
-1 -1
Sample Output
Case 1 is a tree.
Case 2 is a tree.
Case 3 is not a tree。 问题分析:题目要求判断是否为树,先理清是树的条件,树是一种无向简单连通图
1.无回路和环 也就是说(1,2)(2,1)或者(1,1)或者(1,5)(1,5)这些情况都是不行的。
2.要点与点之间连通,而且注意空树(即无点无边的树)也是树。
#include "cstdio"
struct node
{
int i;
int j;
};
node a[],b[];
int number,time=;
int nbegin()
{
int i=;
time++;
while (scanf ("%d%d",&a[i].i,&a[i].j)&& (a[i].i != - || a[i].j != -))
{
number = i;
if (a[i].i || a[i].j)
i++;
else
return ;
}
return ;
}
void tree()
{
int now,next,q;
node y;
if (a[number].i == && a[number].j == && number == )
{
printf ("Case %d is a tree.\n",time);
return;
}
for (int i=;i<number;i++)
{
for (int k=;k<number;k++)
{
if (a[i].j == a[k].j && i != k)
{
printf("Case %d is not a tree.\n",time);
return;
}
if (a[i].i == a[k].j && a[i].j == a[k].i)
{
printf("Case %d is not a tree.\n",time);
return;
}
}
}
for (int i=;i<number;i++)
{
now=;
next=;
q=;
for (int t=;t<number;t++)
if (a[t].i == a[i].i )
{
b[next++] = a[t];
q++;
}
while (next != now)
{
y = b[now];
now++;
for (int j=;j<number;j++)
if (y.j == a[j].i && y.i != a[j].j)
{
b[next++] = a[j];
q++;
}
}
if (q == number)
{
printf ("Case %d is a tree.\n",time);
return;
}
}
printf("Case %d is not a tree.\n",time);
}
int main()
{
while(nbegin())
tree();
return ;
}
暑假集训(2)第一弹 -----Is It A Tree?(Poj308)的更多相关文章
- 暑假集训(4)第一弹 -----递推(Hdu2039)
题意梗概:fff团团员小A想退团了,不过要退团,他必须绘制出贤者法阵,以证明他有资格不受大fff之灵的监督 并退团,小A他现在要开始收集材料了,但是,他不清楚应该买多少份材料. 虽然你并不想帮他退团, ...
- 暑假集训(1)第一弹 -----士兵队列训练问题(Hdu1276)
Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行一至三报数,凡报 ...
- 暑假集训(5)第一弹——— Super Jumping! Jumping! Jumping!(hdu1087)
题意概括:在上次与娑殚的三次博弈中,你们都取得了胜利.便向娑殚提出要求,借助他的力量,传送到一个安全的地方. 你们的愿望达成了,不过,你和小A似乎失散了. 街上人来人往的特别热闹,每一个人的脸上都洋溢 ...
- 暑假集训(3)第一弹 -----还是畅通工程(hdu1233)
题意梗概:N(n<100)个村子想要富起来,自然就要先修路,不过到底还是没富起来,所以陷入了一个怪圈 :资金不足->修不起路->资金不足...... 为了实现走向全民小康社会,全面实 ...
- 暑假集训(3)第二弹 -----Jungle Roads(Hdu1301)
问题梗概:自从上次某个acmer来设计了拉格瑞圣岛的交通路线后,岛上的酋长就相当苦恼,他发现,虽然这些修好的公路便利了岛上的 交通,并且让拉格瑞圣岛的旅游业更加兴旺,甚至他们还收到了一笔不小的国际资金 ...
- 暑假集训(4)第二弹 -----递推(hdu2254)
题意概括:上次小A在你的帮助下成功炼成贤者法阵的第一部分——三角分隔,现在他准备绘制法阵的第二部分——莫测矩形. 而他又遇到了一个问题,他不知道不同矩形到底有多少个. 秉持帮人帮到底,送佛送到西的基本 ...
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:20000KB ...
- 暑假集训(5)第二弹———湫湫系列故事——减肥记I(hdu4508)
问题描述:舔了舔嘴上的油渍,你陷在身后柔软的靠椅上.在德源大赛中获得优胜的你,迫不及待地赶到“吃到饱”饭店吃到饱.当你 正准备离开时,服务员叫住了你,“先生,您还没有吃完你所点的酒菜.”指着你桌上的一 ...
- 暑假集训(2)第九弹 ----- Points on Cycle(hdu1700)
Points on Cycle Time Limit:1000MS Memory Limit:32768 ...
随机推荐
- HDU3695 - Computer Virus on Planet Pandora(AC自动机)
题目大意 给定一个文本串T,然后给定n个模式串,问有多少个模式串在文本串中出现,正反都可以 题解 建立好自动机后.把文本串T正反各匹配一次,刚开始一直TLE...后面找到原因是重复的子串很多以及有模式 ...
- POJ1401 - Factorial
题目大意 N!末尾0的个数 题解 0只能由2*5产生,所以只要求2,5有多少对即可,又因为10!中5的个数少于2,所以只要求因子5有多少个即可,答案即为N/5+N/25+N/125.. 代码: #in ...
- 极客技术专题【008期】:CSS3核心技术:选择器
日期:2013-8-19 来源:GBin1.com 技术专题介绍 技术专题:CSS3核心技术:选择器 专题演讲稿:CSS3选择器 分享人:知名前端技术博客 - w3cplus.com 博主 - 大漠 ...
- Spring源码入门——AnnotationBeanNameGenerator解析
---恢复内容开始--- 接上篇,上篇解析了DefaultBeanGenerator生成bean name的过程(http://www.cnblogs.com/jason0529/p/5272265. ...
- Android模拟器如何加载本机地址及访问本机服务器
首先获取本机ip地址: 在cmd 命令窗口中输入 ipconfig 查看本地电脑ip地址如下: 获取服务器上的Json数据,并返回结果,部分代码如下: 注:StreamUtils是自定义的一个工具类, ...
- weapon制作武器
weapon制作武器 (weapon.pas/c/cpp) 解题报告 制作武器weapon.pas/c/cpp) 背景 WZland的紧急避难所很快就建好了,WZland的居民们陆续地来到这个紧急避难 ...
- 适合高级Java程序员看的12本书
1.Thinking in Java 2.Head First Java 3.Java in a Nutshell 4.The elements of Java style 5.Effective J ...
- Sublime 格式化代码 快捷键以及插件使用
来自Vic___:http://blog.csdn.net/vic___ 其实在sublime中已经自建了格式化按钮: Edit -> Line -> Reindent 只是sub ...
- HashMap早知道
第一眼hashmap始终Collection那个地点 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGxmMTIzMzIx/font/5a6L5L2T/f ...
- 数据持久层(三)ODB介绍
ODB: C++ Object-Relational Mapping (ORM) ODB is an open-source, cross-platform, and cross-database o ...