works part-time at the Centre for Disease Control and Prevention (CDC), where he researches the spread of diseases. An unknown pathogen has just broken out and is determined to save the world!
The CDC's model of the world consists of countries numbered through , represented by points on a 2-D coordinate plane. Country is located at integral coordinates .
Through extensive research, is located at and country is located at , it will take hours for country to be infected after the initial infection of country . The source of the breakout, country , is infected at the -th hour.
has determined a vital piece of information: the time in hours it takes for the pathogen to spread from one country to another is equal to the square of the distance between the two countries. For example, if countryIn order to take preventative measures, queries of the following form:
has been tasked with projecting the rate of infection. Specifically, he has to answerHow many countries will be infected after hours?
Unfortunately,
isn't taking data management this semester, so he's at a total loss. Help him save the world!Constraints
Subtask 1 [20%]
,
,
Subtask 2 [30%]
,
,
Subtask 3 [50%]
,
,
Input Specification
The first line of input will contain , the number of countries.
The next lines will contain and , the coordinates of the -th country, it is guaranteed that no two countries will have the same coordinates.
The next line will contain , the source of the breakout.
The next line will contain , the number of queries.
The next lines will each contain a query.
Output Specification
For each query, output the answer on a new line.
Sample Input
4
2 2
0 3
5 1
4 0
1
4
8
10
4
7
Sample Output
3
4
1
2
Explanation for Sample Output
After hours, the pathogen has not yet spread from its source, therefore the answer is . After hours, country is infected. After hours, country is also infected. At hours, the pathogen has spread from country to country .
Comments
Assuming the first test case is the test case, my clipped output does not match my output in the compiler. My program prints out "3 4 1 2" (on different lines) but the clipped output says "1 1 1 1" (on different lines).
Your code has undefined behaviour. Your visited array needs to be initialized to a value, or else it will take whatever garbage values are currently stored at that memory address.
For the explanation for sample output, shouldn't the time it takes to get to country 2 be 5 hours, not 7 hours?
No, it's simply referring to the query, since the explanation is not written in chronological order
EDIT Make sure you use correct types!
Why are so many people (including myself) getting runtime error? :'(
It's very expensive memory-wise to maintain a priority queue of up to edges. Even if I raise the memory limit to 1 GB, your solution will TLE. The editorial might help you.
Edit: I think it depends on which judge your submission was run on. 64-bit judges will give you RTE and 32-bit judges will give you TLE.
It's probably because you're initializing a
long long
array of elements, although I didn't look at your code in detail enough to be sure.Since a
long long
takes up bits of memory and you're allocating of them, that means you're using up bits, or bytes, or . That should technically pass the memory limit, maybe? But you'd be cutting it close with all of your other variables and arrays.Be aware that if you wanted mathematical rigor, you should have specifically asked for Bruce or Jason's help. :)
Anyway, that might be why, or maybe I'm totally off. Cheers!
Bruce or Jason's help lol
If you're getting TLE on Python, try using multiplication instead of power.