Coding Challenge

Graph Valid Tree

Medium
graphunion-finddfs

Check whether an undirected graph is a tree.

Given n nodes and undirected edges, return true if the graph forms a valid tree.

Examples

Input: n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]

Output: true

Constraints

  • A tree must be connected and acyclic

Preparing your coding workspace...