You are provided with n nodes labeled 0 through n - 1, together with a list of undirected edges where each entry edges[i] = [a, b] joins node a to node b.
Determine whether these edges constitute a single, valid tree — meaning the entire graph is fully connected and contains no cycles. Return true if it does; return false otherwise.
Example 1
Input: n = 4, edges = [[0,1],[1,2],[1,3]]
Output: true
Explanation: Node 1 links to the other three nodes, and there is no cycle.
n = 4 edges = [[0,1], [1, 2], [1, 3]]
true
Input: 4 nodes, edges = [[0,1],[1,2],[1,3]].
Example 2
Input: n = 4, edges = [[0,1],[1,2],[2,0],[2,3]]
Output: false
Explanation: Nodes 0, 1, and 2 create a cycle.
Example 3
Input: n = 4, edges = [[0,1],[2,3]]
Output: false
Explanation: Although there are no cycles, the set {0, 1} and the set {2, 3} form two disconnected components.
Example 4
Input: n = 1, edges = []
Output: true
1 <= n <= 20000 <= edges.length <= 5000edges[i].length == 20 <= a, b < na != bn = 4 edges = [[0,1], [1, 2], [1, 3]]
true
Input: 4 nodes, edges = [[0,1],[1,2],[1,3]].