Is It A Tree?
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 31698 Accepted: 10765
Description
A tree is a well-known data structure that is either empty (null, void, nothing) or is asetofoneor 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 toit.
There is a unique sequence of directed edges fromthe root toeach node.
For example, consider the illustrations below, in which nodes are represented by circles and edges are represented bylineswith arrowheads. The firsttwoof these are trees, but thelast is not.
In this problem you will be given several descriptions of collections of nodes connected by directed edges. For eachof these you are to determine ifthe collection satisfies the definition ofa tree ornot.
Input
The input will consist ofa sequence of descriptions (test cases) followed bya pair of negative integers. Each test case will consist ofa sequence of edge descriptions followed bya pair of zeroes Each edge description will consist ofa pair of integers; thefirstinteger identifies the node from which the edge begins, andthesecondinteger identifies the node to which the edge is directed. Node numbers will always be greater than zero.
Output
For each test case display theline"Case k is a tree."ortheline"Case k is not a tree.", where k corresponds tothe test casenumber (they are sequentially numbered starting with1).
Sample Input
68535264560081736289757478760038686453565200
-1 -1
Sample Output
Case 1 is a tree.
Case 2 is a tree.
Case 3 is nota tree.
Is It A Tree?Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 31698 Accepted: 10765DescriptionA tree is a well-known data structure that is either empty (null, void, nothing) or