#C7923. Count Exchange Groups
Count Exchange Groups
Count Exchange Groups
This problem involves counting the number of exchange groups in a network. You are given \(N\) persons labeled from 1 to \(N\), and \(M\) pairs of direct connections. Two persons belong to the same exchange group if they can be connected directly or indirectly through these pairs. Your task is to compute the number of distinct exchange groups.
inputFormat
The input is given from standard input (stdin) and has the following format:
- A single line containing two space-separated integers \(N\) and \(M\), where \(N\) is the number of persons and \(M\) is the number of connection pairs.
- Then follow \(M\) lines, each containing two space-separated integers \(a\) and \(b\), representing a direct connection between person \(a\) and person \(b\).
outputFormat
Output a single integer to standard output (stdout), which is the number of distinct exchange groups.
## sample5 3
1 2
2 3
4 5
2
</p>