You are given a graph that started as a tree with n nodes labeled 1 to n. One additional edge was added to this tree. The graph is represented as an array edges where edges[i] = [u, v] indicates an edge between nodes u and v.
Return the last edge that was added to the graph that creates a cycle. If there are multiple valid answers, return the edge that appears last in the input.
1 - 2
| |
+---+ (edge [1,2] creates the cycle)
|
3
Input: edges = [[1,2],[1,3],[2,3]] Output: [2,3] Explanation: Adding edge [2,3] creates a cycle because 2 and 3 are already connected through 1.
1 / 2 3 / 4 5 (edge [1,4] is added, creating a cycle 1-2-4-1)
Input: edges = [[1,2],[2,3],[3,4],[1,4],[1,5]] Output: [1,4] Explanation: Edge [1,4] creates a cycle because 1 and 4 are already connected via 1-2-3-4.
n == edges.length3 <= n <= 10001 <= edges[i][0], edges[i][1] <= nedges[i][0] != edges[i][1]edges = [[1,2],[1,3],[2,3]]