How Do I do this?
A tree is a connected undirected graph with no loops. ie; if you choose any 2 nodes (u & v) from the given graph containing ānā nodes, there should be only one way to go from u -> v or v -> u.
So you need to apply a graph traversal technique to check if the graph is connected and then check if it has (n - 1) edges.