solve(n, edges) — n nodes labelled 0..n-1 and a list of undirected
edges. Return true if the edges form a valid tree: connected, with no cycle.
Two facts make this short: a tree on n nodes has exactly n - 1 edges, and a
graph with n - 1 edges is a tree exactly when it has no cycle. Union–Find detects
a cycle the moment an edge joins two nodes that are already connected.
Examples
solve(5, [[0,1],[0,2],[0,3],[1,4]]) → true
solve(5, [[0,1],[1,2],[2,3],[1,3],[1,4]]) → false // cycle 1-2-3
solve(4, [[0,1],[2,3]]) → false // two components
solve(1, []) → trueSample tests