check if an undirected graph is a tree