Problem 174
Find Center of Star Graph
Easy · 10 pts · Graph
Problem
A star graph with N nodes has one centre node that is connected to each of the other N - 1 nodes, and no other edges. You are given the N - 1 edges of a star graph. Print its centre. The centre appears in every edge, so you only need to look at the first two edges: the node they have in common is the centre.
Input
First line: integer N. Next N - 1 lines: an edge u v.
Output
Print the center node.
Constraints
3 <= N <= 100000
Example input
4 1 2 2 3 4 2
Example output
2
Explanation
The edges are 1-2, 2-3 and 4-2. Node 2 is in every edge, so the centre is 2.