Solution:
Answer: 2n(n+1)
We represent the problem as a graph with vertices G1,…,Gn,B1,…,Bn such that there is an edge between vertices Gi and Bj if and only if (Gi,Bj) is suitable, so we want to maximize the number of edges while having a unique matching.
We claim the answer is 2n(n+1). First, note that this can be achieved by having an edge between Gi and Bj for all pairs j≤i, because the only possible matching in this case is pairing Gi with Bi for all i.
To prove that this is maximal, we first assume without loss of generality that our unique matching consists of pairing Gi with Bi for all i, which takes n edges. Now, note that for any i,j, at most one of the two edges GiBj and GjBi can be added, because if both were added, we could pair Gi with Bj and Gj with Bi instead to get another valid matching. Therefore, we may add at most (2n)⋅1=2n(n−1) edges, so the maximal number of edges is n+2n(n−1)=2n(n+1) as desired.