#P2504. Monkey Tree Foraging

    ID: 15774 Type: Default 1000ms 256MiB

Monkey Tree Foraging

Monkey Tree Foraging

In a tropical rainforest, there are N trees whose crowns are above the water after a heavy rain. These trees are represented as points on a 2D coordinate system. There are also M monkeys. Each monkey has a maximum jumping distance given. A monkey can jump from one tree to another if the Euclidean distance between the two trees is at most its jump distance. Since the monkeys cannot swim, in order to forage on every tree crown, a monkey must be able to travel between any two trees (possibly via intermediate trees).

Let the trees be represented as points \( (x_i, y_i) \) for \( i=1,2,\ldots,N \). For a given monkey with maximum jump distance \( L \), it can visit all trees if and only if the graph where vertices are trees and an edge exists between tree \( i \) and tree \( j \) if \( \sqrt{(x_i-x_j)^2+(y_i-y_j)^2} \leq L \) is connected. It can be shown that the minimum jump distance required for full connectivity is equal to the maximum edge weight in the Minimum Spanning Tree (MST) of the trees. That is, if we compute the MST of the complete graph on the trees (with edge weights as Euclidean distances) and let \( d_{req} \) be the maximum edge length in the MST, then a monkey can visit all trees if and only if \( L \geq d_{req} \).

Your task is to count how many monkeys have a maximum jump distance that is at least \( d_{req} \). Note that if there is only one tree, then the monkey does not need to jump at all and can obviously visit all trees.

Input Format: The first line contains two integers N and M. The next N lines each contain two numbers representing the coordinates of a tree. The next M lines each contain one number representing the maximum jump distance of a monkey.

Output Format: Output a single integer representing the number of monkeys that can visit all trees.

Note: All formulas are provided in LaTeX format. For example, the Euclidean distance between tree i and tree j is given by \(\sqrt{(x_i - x_j)^2 + (y_i - y_j)^2}\).

inputFormat

The first line contains two integers N and M, the number of trees and monkeys respectively. The following N lines each contain two space-separated numbers which are the \(x\) and \(y\) coordinates of a tree. The next M lines each contain one number representing the maximum jump distance of a monkey.

outputFormat

Output a single integer: the number of monkeys that can visit all the trees based on their jump capability.

sample

3 4
0 0
0 3
4 0
3
4
5
1
2