Is It A Tree?(待做)

题目描述

A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties. 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.

输入描述:

The input will consist of a sequence of descriptions (test cases) followed by a pair of negative integers. Each test case will consist of a sequence of edge descriptions followed by a pair of zeroes Each edge description will consist of a pair of integers; the first integer identifies the node from which the edge begins, and the second integer identifies the node to which the edge is directed. Node numbers will always be greater than zero and less than 10000.

输出描述:

For each test case display the line "Case k is a tree." or the line "Case k is not a tree.", where k corresponds to the test case number (they are sequentially numbered starting with 1).

示例1

输入

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

输出

Case 1 is a tree.
Case 2 is a tree.
Case 3 is not a tree.
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,812评论 0 10
  • 今天第11天,刚好看到一篇日耕到11天要放弃的。 虽然我这10天也是绞尽脑汁,还在凑字数的阶段,但是没有一开始那么...
    一年后的自己2019年1月28阅读 172评论 0 0
  • 每日践行正面管教 大家好,我是正面管教家长讲师Ivy Ding,我陪大家一起践行正面管教。我第30天打卡,相信大家...
    小妖丁儿阅读 448评论 0 0
  • 今天又来和大家分享心得了。之前在教育孩子的问题上我分享过相信的力量,榜样的力量,今天我想要和大家分享一下赞美的力量...
    学慧爱阅读 473评论 1 1
  • "你他妈给我滚出去"听到这句话有人马上瞪红了眼,有人会拿起身边的异物朝对方扔了过去,当然也有人真的滚了出去...
    亦凡_阅读 249评论 0 2

友情链接更多精彩内容