Redundant Connection

MediumGraphs
Next
GraphUnion FindCycle Detection

A tree with n nodes (labelled 1 to n) had one extra edge added, creating exactly one cycle. Given the n edges, find an edge that can be removed so the graph becomes a tree again. If several edges qualify, print the one that appears last in the input.

Input

Line 1: n. Next n lines: u v, an undirected edge.

Output

Print the edge to remove as 'u v', exactly as it appears in the input.

Constraints

3 <= n <= 1000

Example 1
Input
3
1 2
1 3
2 3
Output
2 3

Edge 2 3 completes the triangle.

Hints

Redundant Connection - Medium Graphs Problem | Skill Shiksha