Imagine a star-shaped network where one central hub connects to every other node, but no other connections exist between the outer nodes. This is called a star graph!
You're given an undirected star graph with n nodes labeled from 1 to n. In a star graph, there's exactly one center node that connects to all other n-1 nodes, forming a perfect star pattern โญ.
Your task is to identify which node is the center of this star graph. You'll receive a 2D array edges where each edges[i] = [ui, vi] represents an undirected edge between nodes ui and vi.
Goal: Return the label of the center node.
Key insight: Since it's guaranteed to be a star graph, the center node will appear in every single edge, while all other nodes appear in exactly one edge!
Input & Output
Constraints
- 3 โค n โค 105
- edges.length == n - 1
- edges[i].length == 2
- 1 โค ui, vi โค n
- ui โ vi
- The given input is guaranteed to be a valid star graph