#C5685. Unique Device Set Partitioning
Unique Device Set Partitioning
Unique Device Set Partitioning
You are given a series of connections between devices. Each connection is represented by a pair of positive integers indicating that the two devices are directly connected. Two devices belong to the same group if they are directly or indirectly connected. Your task is to determine the number of unique groups (or sets) of connected devices.
Note: The input only provides connections. Any device that does not appear in any pair is not considered.
inputFormat
The first line contains a single integer n
, the number of device pairs. Each of the following n
lines contains two space-separated positive integers a
and b
, representing a direct connection between device a
and device b
.
outputFormat
Output a single integer representing the number of unique groups of connected devices.
## sample3
1 2
3 4
2 3
1