#C5704. Count Intersection Clusters

    ID: 49383 Type: Default 1000ms 256MiB

Count Intersection Clusters

Count Intersection Clusters

You are given N intersections in a 2D plane, each defined by its coordinates. Two intersections are considered connected if the Euclidean distance between them is at most D. A cluster is defined as a set of intersections such that any two intersections in the cluster can be connected via a sequence of intersections in the cluster. 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} ]

Your task is to compute the number of distinct clusters.

Note: Input is provided via standard input (stdin) and output should be written to standard output (stdout).

inputFormat

The first line contains two integers N and D separated by a space, where

  • N (2 ≤ N ≤ 100000) is the number of intersections.
  • D (1 ≤ D ≤ 1000) is the maximum allowed distance to consider intersections as connected.

Then follow N lines, each containing two integers X and Y (\(-10^6 \le X, Y \le 10^6\)) representing the coordinates of an intersection.

outputFormat

Output a single integer representing the number of distinct clusters.

## sample
5 2
1 1
2 2
3 3
10 10
11 11
2