#C8490. Counting Distinct Groups
Counting Distinct Groups
Counting Distinct Groups
This problem requires you to determine the number of distinct groups formed among a set of residents based on common interests. Each resident is represented as a node, and every given pair of residents indicating a shared interest is an edge in an undirected graph. The task is to count the number of connected components in this graph.
More formally, given \( n \) residents and a list of \( p \) pairs of residents, you are to count the number of groups such that any two residents in the same group are connected directly or indirectly via shared interests.
Note that the parameter \( m \) in the input represents the number of unique interests but is not used to connect the residents.
inputFormat
The first line of input consists of three integers separated by spaces: \( n \) \( m \) and \( p \), where:
- \( n \) is the number of residents.
- \( m \) is the number of unique interests (this parameter is given for completeness and is not used in forming groups).
- \( p \) is the number of pairs that follow.
Each of the following \( p \) lines contains two integers \( u \) and \( v \), representing that resident \( u \) and resident \( v \) share a common interest.
outputFormat
Output a single integer representing the number of distinct groups that can be formed.
## sample5 4 4
1 2
2 3
4 5
3 4
1