After graduated from Nankai University, Mr. AngelClover and his classmates goes to different places all over the world. Now Mr. AngelClover has a project. In this project he needs to know the distance between the nearest two students who knows each other. For simplicity, he will describe the locations of classmates by 2-dimensional coordinates, and the distance measured by Euclid distance. For example, if Jack lives at (3, 5), and Alphard lives at (4, 6), the distance between them is .
However, some students don't know all the other students in our university. Luckily, the monitor knows the class number every student was in. Students who were in the same class know each other. The monitor also knows the courses which class has take. You can assume that students in the same class always take courses together and students can only know each other by taking the same classes together.
Now it's your mission to find out what Mr. AngelClover wants.
Input (Please use standard input, and don’t read or write files.) |
| |
The first line of the input contains three integers N, M, C. N means the number of students, and M means the number of classes and C the number of courses. From the 2nd to the (C+1)th line, each line contains the course name, which is less than eighty letters and all is lower-case letters. An integer K following the course name means number of classes which have taken this course, then follows K numbers represent the classes' number. Then follows N line each line contains three integers Z, X, Y. This means a student who was in Class Z lives at (X, Y). You are guaranteed that 0< N <=105, 0< M <=100, 0<= C <=100, 0<= K <=10, 0< Z <=M, |X|<109, |Y|<109. |
| |
Output (Please use standard output, and don’t read or write files.) |
| |
Output only contains one real number represents the distance Mr. AngelClover wants. You should output the answer with 6 digits after the decimal point. You are guaranteed the answer always exists. |
| |
|
| |
Sample Input | Sample Output | |
5 3 2 math 2 1 2 english 2 1 3 2 0 0 3 1 0 1 0 2 3 3 2 2 4 2
| 2.000000 | |
Hint | ||
The distance between 1st and 3rd students is 2.000000. | ||
没有什么特别的算法。
一个邻接表记录每个课程所有的班级,并且把这些班级按班号从小到大排序。
然后对输入的同学,按班号从小到大排序。用一个数组记录每个班级的第一个同学的位置。
最后,遍历邻接表,根据邻接表一行的班号,对这些班里的同学两两求距离,得出最小的。