Input
Output
Sample test(s)
input
4
3
10
20
30
40
1
3
2
3
4
3
output
16.666667
input
output
input
output
Note
【翻译】
n点m边的无向图,有点权ai
f(p,q):所有路径p -> q的最小点权中的最大值
求所有数对(p,q)(p!=q)的平均值
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define inf 1000000000
#define linf (1LL<<50)
using namespace std;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x*=10;x+=ch-'0';ch=getchar();}
return x*f;
}
int n,m,cnt,f[100005],fa[100005];
ll size[100005];
ll ans;
struct data1{int x,y,v;}a[100005];
inline bool cmp(data1 a,data1 b)
{return a.v>b.v;}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)
f[i]=read(),fa[i]=i,size[i]=1;
for(int i=1;i<=m;i++)
{
a[i].x=read();a[i].y=read();
a[i].v=min(f[a[i].x],f[a[i].y]);
}
sort(a+1,a+m+1,cmp);
for(int i=1;i<=m;i++)
{
int x=find(a[i].x),y=find(a[i].y);
if(x!=y)
{
ans+=a[i].v*size[x]*size[y];
size[x]+=size[y];
fa[y]=x;
}
}
ll tmp=(ll)n*(n-1)/2;
double ans2=(double)ans/tmp;
printf("%.6lf",ans2);
return 0;
}