Question: give you a few balls of the ball's heart and radius to establish a path between the balls. So that each ball can be directly or indirectly reached. Practice: regard each ball as a point, find the distance between each two points, and then generate the minimum tree algorithm., [Html] # include <iostream> # include <stdio. h> # include <string. h> # include <algorithm> # include <math. h ># define INF 99999999 using namespace std; struct list {double x; double y; double z; double r ;}point [100001]; double juli (int I, int j) {double len; len = sqrt (point [I]. x-point [j]. x) * (point [I]. x-point [j]. x) + (point [I]. y-point [j]. y) * (point [I]. y-point [j]. y) + (point [I]. z-point [j]. z) * (point [I]. z-point [J]. z); if (len-point [I]. r-point [j]. r <0) return 0; return len-point [I]. r-point [j]. r;} int main () {int I, j, n; double map [101] [101]; while (scanf ("% d", & n) {memset (map, 0, sizeof (map); for (I = 0; I <n; I ++) {cin> point [I]. x> point [I]. y> point [I]. z> point [I]. r ;}for (I = 0; I <n; I ++) {for (j = 0; j <n; j ++) {if (I! = J) {map [I] [j] = juli (I, j) ;}} double low [101]; int visit [101]; memset (visit, 0, sizeof (visit); visit [0] = 1; for (I = 0; I <n; I ++) {low [I] = map [0] [I];} double sum; sum = 0; for (I = 0; I <n; I ++) {double min; int ipos; min = INF; for (j = 0; j <n; j ++) {if (! Visit [j] & min> low [j]) {min = low [j]; ipos = j ;}} if (min = INF) break; sum + = min; visit [ipos] = 1; for (j = 0; j <n; j ++) {www.2cto.com if (low [j]> map [ipos] [j]) {www.2cto.com low [j] = map [ipos] [j] ;}} printf ("%. 3f \ n ", sum);} return 0 ;}