medium
graph
union-find
A connected undirected graph started as a tree, then one extra edge was added. Return the last input edge that can be removed to restore a tree.
Examples
Example 1
Input: edges = [[1,2],[1,3],[2,3]]
Output: [2,3]
Example 2
Input: edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]
Output: [1,4]
Example 3
Input: edges = [[1,2],[2,3],[3,1]]
Output: [3,1]
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.