The Sun-Eater's Meal

0

0 votes
Basic Programming, cakewalk, Very-Easy
Problem

In Brightest Day, In Blackest Night!

Hal Jordan, the Green Lantern of Sector 2814, is in trouble. A sun eater has consumed several stars in his patrol area. When a star in the galaxy is extinguished, it has very negative effects near the star. All life in planets of that star's system gets extinguished. Hal has stopped the sun eater from causing further damage, but he wishes to calculate how many planets have been affected by the sun eater's meal of destruction.

Given a description of the stars and the planets in sector 2814 of the galaxy, calculate how many planets have been affected by the sun eater.

NOTE: A planet may be part of systems of zero or more stars. A planet is connected affected if any of the stars whose system it belongs to has been eaten by the sun-eater

INPUT:

The first line of each input file consists of the number of test cases (t).

The first line of each test case contains two integers, n - the number of stars and m - the number of planets

Then, n lines follow each containing four integers in the following format:

x y radius eaten - Here x and y are x and y co-ordinates of the star, radius is the radius of the star's system and eaten is 0 or 1 depending on whether the sun eater has eaten this star or not (0 - not eaten, 1 - eaten)

Then m lines follow each containing two integers in the following format:

px py - Here px and py are the x and y co-ordinates of the planet

OUTPUT:

For each test case, print the number of planets that have been affected by the sun eater.

CONSTRAINTS:

1 <= t <= 10

1 <= n, m <= 1000

1 <= radius <= 10000

1 <= x, y, px, py <= 10000

eaten = 0 or 1

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Only the 3rd planet is affected as it lies in the system of the 2nd star.

Editor Image

?