Is It A Tree?(待做)

作者: IceFrozen | 来源:发表于2019-01-20 19:03 被阅读0次
题目描述

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.

相关文章

  • Is It A Tree?(待做)

    题目描述 A tree is a well-known data structure that is either...

  • FFmpeg API-常用数据结构和函数

    目录 参考 1. 参考 [1] FFmpeg/tree/release/4.1 待整理... av_log_set...

  • 待做

    Json和File同时传递,怎么进行处理sql server中的数据类型与java类型的对应关系

  • Linux非常漂亮的tree命令

    apt install tree 把tree的结果输出到tree.txt文件tree > tree.txt

  • cmd tree 命令生成文档结构树

    tree .tree >tree.txttree >>tree.txttree /atree /f// 遍历层级t...

  • 待做列表

    pages blog sync zk-kafka-分词-生词 mis+mongo查询访问记录

  • 待做LIST

    【关于艺术】 艺术家驻留 查询20世纪西方文化政治运动 【关于诗歌】 诗歌的分类 当代诗歌及现代诗 外国诗歌的分类...

  • 待做之事

    下学期空闲时间也比较多,可以做什么呢? 1 大外的课 2 读书,学习,科研,写论文(课程思政),要花大量大量的时间...

  • Binary Tree(1)

    Tree Node Binary Tree Representation in C: A tree is repr...

  • Tree At My Window

    Tree At My Window Robert Frost Tree At My Window Tree at ...

网友评论

    本文标题:Is It A Tree?(待做)

    本文链接:https://www.haomeiwen.com/subject/mnqfjqtx.html