Given n nodes labeled 0 to n-1 and a list of undirected edges, determine whether these edges form a valid tree. A valid tree has exactly n-1 edges and is fully connected with no cycles.
A valid tree must have exactly n-1 edges AND be connected. Use Union-Find: if any edge creates a cycle (both nodes already connected), return false.
- If edges.length != n-1: return false.
- Union-Find on n nodes.
- For each edge: if same component already (find(u)==find(v)): cycle detected, return false.
- Else union. Return true.
- Time Complexity: O(N + E)
- Space Complexity: O(N)