Online Programming Server

Login

Login with facebook [?]

Facebook

Problem 1098: Wireless communication

Problem ID 1098
Title Wireless communication
pdf  
Description
In Byteland, machine communicate via wireless technology. Therefore, there are many radio towers installed
in Byteland. Limited by power supply, each tower has its maximum transmit distance, denoted by ri.
We say two tower i and j can communicate directly if their distance between them is no larger than ri and rj . The distance here is defined as euclidean distance, which is
((xi + xj)2 + (yi + yj)2)0.5. Two towers
i and j can communicate if they can communicate directly, or there exists a tower k such that i and k can
communicate and k and j can communicate.
Alice and Bob wants to communicate. Lets assume Alice is located at tower 1 and Bob is located at tower
N. They are going to choose a subset of tower such that 1 and N can communicate. Moreover, they hope that the subset can be as small as possible because they are afraid that the message will be overheard by someone.
Input
The first line contain an integer T(1 ≤ T ≤ 20), the number of test cases.
For each test cases, the first line contains an integer N (2 ≤ N ≤ 500), the number of towers.
Followed by N lines, each lines contains 3 integers xi, yi, ri (0 ≤ xi, yi, ri ≤ 10000).

The position of all towers are distinct.
Output
For each test cases, output the minimum tower involved (including tower 1 and N). If it is impossible for them to communicate, output -1.
Sample Input
2
5
0 0 3
2 1 1
0 3 2
1 2 4
3 3 3
5
0 0 3
2 1 1
0 3 2
1 2 2
3 3 3
Sample Output
3
-1
Hint
 
Last Modified 2012-05-30 15:12:05
Time Limit 1 seconds
Memory Limit 64 MB
Accepted Solutions 0
Submitted Solutions 0
Difficulty Factor 200