You have a graph of n nodes labeled from 0 to n - 1 and a list of undirected edges, where edges[i] = [a_i, b_i] indicates an undirected edge between nodes a_i and b_i.
Return true if the edges make up a valid tree, and false otherwise.
Recall that an undirected graph on n vertices is a valid tree if and only if it is fully connected and contains no cycles (equivalently, it has exactly n - 1 edges and all n nodes belong to a single connected component).
Input / output
n: int, edges: int[][]boolean1 <= n <= 20000 <= edges.length <= 5000edges[i].length == 2, 0 <= a_i, b_i < n, a_i != b_iCompare DFS/BFS traversal against Union-Find (Disjoint Set Union): which one lets you detect cycles incrementally if edges arrive as a stream?