Given
n vertices and an array of undirected edges edges. Return true if the graph is a valid tree (connected and acyclic).Example 1
Input: n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]
Output: true
Explanation: Connected acyclic graph with 5 vertices.
Output: true
Explanation: Connected acyclic graph with 5 vertices.
Example 2
Input: n = 5, edges = [[0,1],[1,2],[2,3],[1,3],[1,4]]
Output: false
Explanation: There is a cycle — not a tree.
Output: false
Explanation: There is a cycle — not a tree.