Loading...
Given n nodes (0 to n-1) and a list of undirected edges, check if these edges form a valid tree (connected, no cycles).
Input: first line = n, second = edges as u:v comma-separated (or 'none').
5 0:1,0:2,0:3,1:4
True
5 represents the number of nodes in the graph, and the edges are given as 0:1,0:2,0:3,1:4, which can be represented as a list of pairs: (0,1), (0,2), (0,3), (1,4).0 visits all nodes (0, 1, 2, 3, 4), indicating the graph is connected.True.