Assume there are multiple countries on a planet,
represented by a list of pairs of countries, e.g., <A, B>,
indicating that countries A and B are allies.
Design Requirements:
Design a data structure that can efficiently handle the following operations:
- Initialize the data structure with a list of pairs of countries, each pair representing an alliance (e.g., <A, B>).
- Check if two countries <M, N> are allies, either directly or indirectly through a chain of alliances.
- Add a new alliance between any two countries <X, Y>, updating the data structure to reflect this change.
- Return the number of distinct groups where all countries in a group are connected through alliances.
Comments (1)


