(xn,yn) on the plane and a non-negative integer boundary k. Each point is a tiny steel ball and k is the draw in force of a ball when it's charged. The draw in power is something very similar for all balls.    In one activity, you can choose a ball I to charge it. When charged, all balls with Manhattan distance all things considered k from ball I move to the situation of ball I. Many balls may have a similar facilitate

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

Correct answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science.

You have n particular focuses (x1,y1),… ,(xn,yn) on the plane and a non-negative integer boundary k. Each point is a tiny steel ball and k is the draw in force of a ball when it's charged. The draw in power is something very similar for all balls. 

 

In one activity, you can choose a ball I to charge it. When charged, all balls with Manhattan distance all things considered k from ball I move to the situation of ball I. Many balls may have a similar facilitate after an activity. 

 

All the more officially, for all balls j with the end goal that |xi−xj|+|yi−yj|≤k, we dole out xj:=xi and yj:=yi. 

 

An illustration of an activity. Subsequent to charging the ball in the middle, two different balls move to its position. On the right side, the red dab in the middle is the normal situation of those balls. 

 

Your errand is to observe the base number of activities to move all balls to a similar position, or report that this is outlandish. 

 

Input 

 

The principal line contains a solitary integer t (1≤t≤100) — the number of experiments. 

 

The primary line of each experiment contains two integers n, k (2≤n≤100, 0≤k≤106) — the number of balls and the draw in force, everything being equal, individually. 

 

The accompanying n lines portray the balls' directions. The I-th of these lines contains two integers xi, yi (0≤xi,yi≤105) — the directions of the I-th ball. 

 

It is ensured that all focuses are particular. 

 

Output 

 

For each experiment print a solitary integer — the base number of activities to move all balls to a similar position, or −1 in case it is unthinkable.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole