ADA Classes - Depth First Search
Is it a Tree?
Undirected graph without loops and multiple edges is given with the adjacency matrix. Determine whether the graph is a tree.
The first line contains the number of vertices n (1 ≤ n ≤ 100) in the graph. In the next lines the adjacency matrix of size n × n is given, where 1 denotes the presence of an edge, and 0 its absence. The matrix is symmetric with respect to the main diagonal.
Print the message YES, if the graph is a tree, and NO otherwise.
3 0 1 0 1 0 1 0 1 0