We are given a “tree” in the form of a 2D-array, with
distinct values for each node.
In the given 2D-array, each element pair
[u, v] represents that
v is a child of
u in the tree.
We can remove
exactly one redundant pair in this “tree” to make the result a tree.
You need to find and output such a pair. If there are multiple answers for this question, output the one appearing last in the 2D-array. There is always at least one answer.
The size of the input 2D-array will be between 1 and 1000.
Every integer represented in the 2D-array will be between 1 and 2000.