#C3843. Molecular Bonding Connectivity
Molecular Bonding Connectivity
Molecular Bonding Connectivity
This problem involves determining the number of unique molecules that can be connected by bonds, starting from a given molecule and including all molecules that are indirectly connected. Two molecules are considered bonded if the Euclidean distance between them is at most \(d\). The bonding is transitive: if molecule A is bonded to molecule B, and molecule B is bonded to molecule C, then A, B, and C belong to the same connected group.
For each dataset, you are given the number of molecules \(n\) and the threshold distance \(d\). Then \(n\) lines of coordinates (\(x, y\)) are provided. The input terminates with a line containing "0 0". Your task is to output the number of molecules connected to the first molecule (index 0) for each dataset.
Note: The Euclidean distance between two points \((x_1, y_1)\) and \((x_2, y_2)\) is given by \(\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}\).
inputFormat
Input Format:
- Multiple datasets. For each dataset:
- The first line contains two integers \(n\) (number of molecules) and \(d\) (bonding threshold distance).
- The next \(n\) lines each contain two floating-point numbers representing the coordinates \(x\) and \(y\) of a molecule.
- The input ends with a line containing "0 0" which should not be processed.
outputFormat
Output Format:
- For each dataset, output a single line containing the number of molecules connected to the first molecule (including that molecule) via direct or indirect bonds.
3 10
1.000 1.000
2.000 2.000
15.000 15.000
0 0
2