You have a graph of n nodes labeled 0 to n - 1. You are given an integer n and a list of undirected edges where edges[i] = [a, b] indicates there is an edge between nodes a and b.
Return true if these edges make up a valid tree, and false otherwise.
A valid tree is connected (every node is reachable from every other node) and acyclic (no cycle exists).
0 /|\ 1 2 3 | 4
Input: n = 5, edges = [[0,1],[0,2],[0,3],[1,4]] Output: true Explanation: All 5 nodes are connected and no cycle exists.
0
|
1
/|\
2 | 4
| |
3-+
Input: n = 5, edges = [[0,1],[1,2],[2,3],[1,3],[1,4]] Output: false Explanation: Nodes 1, 2, and 3 form a cycle.
1 <= n <= 20000 <= edges.length <= 50000 <= a_i, b_i < na_i != b_in = 5, edges = [[0, 1], [0, 2], [0, 3], [1, 4]]