#C3662. Counting Hamming Groups
Counting Hamming Groups
Counting Hamming Groups
You are given a collection of binary strings. Two binary strings are said to be connected if the Hamming distance between them is at most \(2\), where the Hamming distance is defined as the number of positions at which the corresponding bits differ. A group is a set of binary strings in which any two strings are connected directly or indirectly (transitively).
Your task is to determine the number of groups formed by the given set of binary strings.
Definition:
Let \(a\) and \(b\) be two binary strings of equal length. The Hamming distance \(d(a,b)\) is defined as:
\[ d(a,b)=\sum_{i=1}^{n} [a_i \neq b_i] \]Two binary strings belong to the same group if \(d(a,b) \leq 2\). Note that connectivity is transitive; that is, if string A is connected to string B, and string B is connected to string C, then A, B, and C all belong to the same group.
inputFormat
The input is read from standard input and is formatted as follows:
- The first line contains an integer \(n\), representing the number of binary strings.
- The following \(n\) lines each contain a binary string of equal length.
outputFormat
Output a single integer representing the number of groups formed by the binary strings.
## sample5
10100
00100
10110
11100
11011
2