Problem # 16 : A tree or not a tree
Write a function TREE(M N A()) to find out whether a given graph is a tree or not.
M stands for the number of nodes (points) and N stands for the number of connections in the graph. If there is a connection between node P & Q then cells A(<connection> 1) and A(<connection> 2) are set to P & Q.
Sample Output
M=5
N=5 (5 stations and 5 connections)
and array A() contains.
| 1 | 2 |
| 1 | 3 |
| 5 | 2 |
| 3 | 4 |
| 3 | 5 |
If M=7
N=6 and array A() has values
| 1 | 2 |
| 1 | 3 |
| 3 | 5 |
| 3 | 4 |
| 6 | 2 |
| 7 | 2 |
if M=8
N=5 and A() contains
| 1 | 2 |
| 1 | 3 |
| 5 | 2 |
| 3 | 4 |
| 6 | 7 |
![]() |