You're given an undirected graph with n nodes and a list of edges. Your task is to find a special formation called a "connected trio" and determine which one has the minimum degree.
What is a Connected Trio?
A connected trio is a group of three nodes where every pair is directly connected by an edge. Think of it as a triangle in the graph - nodes A, B, and C form a trio if there are edges A-B, B-C, and A-C.
What is the Degree of a Trio?
The degree of a connected trio is the count of external edges - edges that have one endpoint inside the trio and the other endpoint outside the trio. Internal edges within the trio don't count!
Goal: Return the minimum degree among all connected trios in the graph, or -1 if no connected trio exists.
Example: If trio {1,2,3} has external connections to nodes 4,5,6,7, and the total external edges are 5, then this trio's degree is 5.
Input & Output
Visualization
Time & Space Complexity
For each edge, check intersection of two adjacency lists. In dense graphs, this approaches O(m√m)
Space for adjacency lists and degree arrays
Constraints
- 2 ≤ n ≤ 400
- edges[i].length == 2
- 1 ≤ edges.length ≤ n * (n-1) / 2
- 1 ≤ ui, vi ≤ n
- ui ≠ vi
- No repeated edges in the input