## Description

During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China -- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the kingdom Qin. Through 9 years of wars, he finally conquered all six other kingdoms and became the first emperor of a unified China in 221 BC. That was Qin dynasty -- the first imperial dynasty of China(not to be confused with the Qing Dynasty, the last dynasty of China). So Ying Zheng named himself "Qin Shi Huang" because "Shi Huang" means "the first emperor " in Chinese.Qin Shi Huang undertook gigantic projects, including the first version of the Great Wall of China, the now famous city-sized mausoleum guarded by a life-sized Terracotta Army, and a massive national road system. There is a story about the road system:

Would you help Qin Shi Huang?

A city can be considered as a point, and a road can be considered as a line segment connecting two points.

## Code

``` 1 #include<cstdio>
2 #include<algorithm>
3 #include<cmath>
4 #include<cstring>
5 using namespace std;
6 const int maxn=1005;
7
8 int f[maxn][maxn],p[maxn];
9 int x[maxn],y[maxn],c[maxn];
10 int find(int x){return p[x]==x?x:p[x]=find(p[x]);}
11 struct edge{
12     int u,v,w;
13     bool operator<(const edge&a)
14         const {return w<a.w;}
15 }g[maxn*maxn];
17 void adde(int u,int v,int g){
20 }
21 int dist(int a,int b){
22     return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
23 }
24 int n,m;
25
26 int q[maxn],clock;
27 void dfs(int p,int u){
28     q[++clock]=u;
30         int v=e[i];
31         if(v==p) continue;
32         for(int j=1;j<=clock;j++)
33             f[v][q[j]]=f[q[j]][v]=max(f[u][q[j]],w[i]);
34         dfs(u,v);
35     }
36 }
37
38 void clear(){
39     m=k=clock=0;
41     memset(e,0,sizeof(e));
42     memset(w,0,sizeof(w));
43     memset(nxt,0,sizeof(nxt));
44     memset(f,0,sizeof(f));
45 }
46
47 int main(){
48     int T;
49     scanf("%d",&T);
50     while(T--){
51     clear();
52     scanf("%d",&n);
53     for(int i=1;i<=n;i++)
54         scanf("%d%d%d",&x[i],&y[i],&c[i]),p[i]=i;
55
56     for(int i=1;i<=n;i++)
57         for(int j=i+1;j<=n;j++){
58             m++;
59             g[m].u=i,g[m].v=j;
60             g[m].w=dist(i,j);
61         }
62     sort(g+1,g+m+1);
63
64     double sum=0;
65     for(int i=1;i<=m;i++){
66         int x=find(g[i].u),y=find(g[i].v);
67         if(x!=y){
69             sum+=sqrt(g[i].w);
70             p[x]=y;
71         }
72         if(k==2*(n-1)) break;
73     }
74
75     dfs(0,1);
76
77     double ans=0;
78     for(int u=1;u<=n;u++)
79         for(int v=u+1;v<=n;v++){
80             double ansx=sum;
81             ansx-=sqrt(f[u][v]);
82             ansx=(c[u]+c[v])*1.0/ansx;
83             ans=max(ans,ansx);
84         }
85     printf("%.2lf\n",ans);
86     }
87     return 0;
88 }```