Graph Valid Tree
Given n nodes labeled from 0 to n - 1 and a list of undirected edges, write a function to check whether these edges make up a valid tree.

30:00

Graph Valid Tree
medium
Topics
Companies

Given n nodes labeled from 0 to n - 1 and a list of undirected edges, write a function to check whether these edges make up a valid tree.

Example 1:
Input: {"n":5,"edges":[[0,1],[0,2],[0,3],[1,4]]}
Output: true
Constraints:
  • 1n20001 \leq n \leq 2000

  • 0edges.length50000 \leq \text{edges.length} \leq 5000

  • edges[i].length==2\text{edges}[i].\text{length} == 2

  • 0ai,bi<n0 \leq a_i, b_i < n

  • aibia_i \neq b_i

  • There are no self-loops or repeated edges.

Input
arr ={"n":5,"edges":[[0,1],[0,2],[0,3],[1,4]]}

Start

0

1

2

3

4

Variables
No variables to display
DepthFunction Call
Stack empty
0/16