195. Graph Valid Tree
MediumGraph
You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [a_i, b_i] indicates that there is an undirected edge between nodes a_i and b_i in the graph. Return true if the edges of the given graph make up a valid tree, and false otherwise.
Examples
Input: 5 [[0,1],[0,2],[0,3],[1,4]]
Output: true
Explanation: 4 edges on 5 nodes, fully connected with no cycle — a valid tree.
Constraints
- 1 <= n <= 2000
- 0 <= edges.length <= 5000
- edges[i].length == 2
- 0 <= a_i, b_i < n
- a_i != b_i
- There are no self-loops or repeated edges.
Loading...
Run checks all cases above. Submit evaluates all test cases.