We are given connected undirected graph of $n$ nodes and $m$ edges. On each node one integer(value) from $0$ to $n-1$ is written.
We need to build tree such that for each node $i$, all nodes in the subtree of $i$ should be reachable from $i$ by going only through edges with values greater than $i$.
Such tree is always rooted at $0$ since all vertices can be reached from $0$.
For example, for the given graph:
(5, 1), (1, 2), (1, 3), (3, 4), (3, 0), (5, 2) The tree we are looking for is rooted at 0 and its edges are: (0, 1), (1, 2), (1, 3), (2, 5), (3, 4)
I have heard that this is solvable with using disjoint data set structure however I couldn't find a way how to properly find a way to connect the components.