|
| 1 | +#include <cmath> |
| 2 | +#include <set> |
| 3 | +#include <list> |
| 4 | +//#include <unordered_set> |
| 5 | +//#include <hash_map> |
| 6 | +#include <climits> |
| 7 | +#include <queue> |
| 8 | +#include <vector> |
| 9 | +#include <map> |
| 10 | +#include <set> |
| 11 | +#include <cstdlib> |
| 12 | +#include <fstream> |
| 13 | +#include <iomanip> |
| 14 | +#include <iostream> |
| 15 | +#include <sstream> // istringstream buffer(myString); |
| 16 | +#include <stack> |
| 17 | +#include <algorithm> |
| 18 | +#include <cstring> |
| 19 | +#include <cassert> |
| 20 | +using namespace std; |
| 21 | +#define bit(x,i) (x&(1<<i)) |
| 22 | +#define lowb(t) (t &(-t)) |
| 23 | +#define pow2(x) (1<<x) |
| 24 | +//#define max(a,b) (a<b?b:a) |
| 25 | +//#define abs(x) (x<0?-x:x) |
| 26 | +#define IN(i,l,r) (l<i&&i<r) |
| 27 | +#define LINR(i,l,r) (l<=i&&i<=r) |
| 28 | +#define LIN(i,l,r) (l<=i&&i<r) |
| 29 | +#define INR(i,l,r) (l<i&&i<r) |
| 30 | +#define F(i,L,R) for (int i = L; i < R; i++) |
| 31 | +#define FE(i,L,R) for (int i = L; i <= R; i++) |
| 32 | +#define FF(i,L,R) for (int i = L; i > R; i--) |
| 33 | +#define FFE(i,L,R) for (int i = L; i >= R; i--) |
| 34 | +#define char2Int(c) (c-'0') |
| 35 | +#define lastEle(vec) vec[vec.size()-1] |
| 36 | +#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) |
| 37 | +#define clr(a,x) memset(a,x,sizeof(a)) |
| 38 | +#define getI(a) scanf("%d", &a) |
| 39 | +#define getII(a,b) scanf("%d%d", &a, &b) |
| 40 | +#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c) |
| 41 | +#define getS(x) scanf("%s", x); |
| 42 | +#define SZ(x) ((int)((x).size())) |
| 43 | +#define REMAX(a,b) (a)=max((a),(b)); |
| 44 | +#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl; |
| 45 | +#define REMIN(a,b) (a)=min((a),(b)); |
| 46 | +#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) |
| 47 | +#define ALL(t) t.begin(),t.end() |
| 48 | +#define ll long long |
| 49 | +#define ull unsigned long long |
| 50 | +#define ui unsigned int |
| 51 | +#define us unsigned short |
| 52 | +#define IOS ios_base::sync_with_stdio(0); |
| 53 | +#define pb push_back |
| 54 | +#define INF 1001001001 |
| 55 | +#define PI 3.1415926535897932384626 |
| 56 | +#define mp make_pair |
| 57 | +#define ll long long |
| 58 | +#define fi first |
| 59 | +#define se second |
| 60 | +#define root(x) ((int)sqrt((double)x)) |
| 61 | +#define wez(n) int (n); scanf("%d",&(n)); |
| 62 | +#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m)); |
| 63 | +#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k)); |
| 64 | +inline void pisz(int n) { printf("%d\n",n); } |
| 65 | +#define TESTS wez(testow)while(testow--) |
| 66 | +#define whileZ int T; getI(T); while(T--) |
| 67 | +#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ') |
| 68 | +#define printM(a,n,m) F(i,0,n){ F(j,0,m) cout << a[i][j] << ' '; cout << endl;} |
| 69 | +#define printV(a) printA(a,0,(int)a.size()-1); |
| 70 | +#define printVV(a) F(i,0,a.size()) {F(j,0,a[i].size())cout << a[i][j] << ' '; cout << endl;} |
| 71 | +#define MAXN 10000 |
| 72 | +#define sz(a) int((a).size()) |
| 73 | +#define pb push_back |
| 74 | +#define all(c) (c).begin(),(c).end() |
| 75 | +#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) |
| 76 | +#define present(c,x) ((c).find(x) != (c).end()) |
| 77 | +#define cpresent(c,x) (find(all(c),x) != (c).end()) |
| 78 | +template<class T> string tos(T n) { stringstream ss; ss << n; return ss.str(); } |
| 79 | +#define tiny (double)1e-13 |
| 80 | +#define close(x,y) (abs(x-y)<tiny) |
| 81 | +typedef int elem_t; |
| 82 | +typedef vector<int> vi; |
| 83 | +typedef vector<vi> vvi; |
| 84 | +typedef pair<int,int> ii; |
| 85 | +template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";} |
| 86 | +template<typename T> ostream& operator<<(ostream &s,vector<T> t){F(i,0,SZ(t))s<<t[i]<<" ";return s; } |
| 87 | +int gcd(int a,int b){return a?gcd(b%a,a):b;} |
| 88 | +ll gcd(ll a,ll b){return a?gcd(b%a,a):b;} |
| 89 | +ll powmod(ll a,ll p,ll m){ll r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;} |
| 90 | +#define N (int)1e5+5 |
| 91 | +int n, m; |
| 92 | +struct node{ |
| 93 | + int label; |
| 94 | + int w; |
| 95 | + bool operator<(const node& other)const{ |
| 96 | + return w < other.w; |
| 97 | + } |
| 98 | +}; |
| 99 | +int w[N]; |
| 100 | +node v[N]; |
| 101 | +vector<int> L[N]; |
| 102 | +int used[N]; |
| 103 | +int cnt; |
| 104 | +int label; |
| 105 | +int dfs(int x){ |
| 106 | + used[x] = label; |
| 107 | + cnt++; |
| 108 | + F(i,0,L[x].size()){ |
| 109 | + int y = L[x][i]; |
| 110 | + if (used[y] != -1 && used[y] != label){ |
| 111 | + dfs(y); |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | +int main ( int argc, char *argv[] ) { |
| 116 | + cin >> n >> m; |
| 117 | + FE(i,1,n) { |
| 118 | + getI(w[i]); |
| 119 | + v[i].w = w[i]; |
| 120 | + v[i].label = i; |
| 121 | + } |
| 122 | + sort(v+1, v+n+1); |
| 123 | + while(m--){ |
| 124 | + wez2(x, y); |
| 125 | + L[x].push_back(y); |
| 126 | + L[y].push_back(x); |
| 127 | + } |
| 128 | + clr(used, 0); |
| 129 | + ll cost = 0; |
| 130 | + label = 0; |
| 131 | + FE(k,1,n){ |
| 132 | + int x = v[k].label; |
| 133 | +// cout << "label : " << x << endl; |
| 134 | + label++; |
| 135 | + used[x] = -1; |
| 136 | + vector<int> num; |
| 137 | + F(i,0,L[x].size()){ |
| 138 | + int y = L[x][i]; |
| 139 | + if (used[y] != -1 && used[y] != label){ |
| 140 | + cnt = 0; |
| 141 | + dfs(y); |
| 142 | + num.push_back(cnt); |
| 143 | + } |
| 144 | + } |
| 145 | + ll c = 0; |
| 146 | + F(i,0,num.size()){ |
| 147 | + c += num[i]; |
| 148 | + if (i != 0){ |
| 149 | + c += num[i] * num[i-1]; |
| 150 | + num[i] += num[i-1]; |
| 151 | + } |
| 152 | + } |
| 153 | +// printV(num); |
| 154 | + cost += c * v[k].w; |
| 155 | +// cout << cost << endl; |
| 156 | + } |
| 157 | + printf("%.6lf\n", ((double) cost)*2/n/(n-1)); |
| 158 | + return EXIT_SUCCESS; |
| 159 | +} |
| 160 | + |
0 commit comments