B. The child and Zootime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
Of course our child likes walking in a zoo. The zoo hasNAreas, that is numbered from1ToN. TheI-th area contains ai Animals in it. Also there ismRoads in the zoo, and each road connects the distinct areas. Naturally the zoo is a connected, so can reach any area of the zoo from any other area using the roads.
We are very smart. Imagine the want to goPTo areaQ. Firstly he considers all the simple routes fromPToQ. For each route the child writes down the number, which is equal to the minimum number of animals among the route areas. Let ' s denote the largest of the written numbers as F(P,? Q). Finally, the child chooses one of the routes for which he writes down the value F(P,? Q).
After the child have visited the zoo, he thinks about the question:what is the average value of F(P, ? q) for all pairs p,? Q (p. ≠? ) Q)? Can you answer his question?
Input
The first line contains integersNandm(2?≤? n? ≤?105 ;0?≤? m. ≤?105 ). The second line containsNIntegers: a1,? a 2,?...,? a N (0?≤? a i? ≤?105 ). Then followmLines, each line contains the integers xi and yi (1?≤? x i,? y i? ≤? N ; xi? ≠? y I ), denoting the road between areas xi and yi .
All roads am bidirectional, each pair of areas is connected by at the most one road.
Output
Output a real number-the value of.
The answer would be a considered correct if its relative or absolute error doesn ' t exceed?-? 4.
Sample Test (s) input
4 310 20 30 401 32 34 3
Output
16.666667
Input
3 310 20 301 22 33 1
Output
13.333333
Input
7 840 20 10 30 20 50 401 22 33 44 55 66 71 45 7
Output
18.571429
Note
Consider the first sample. There is possible situations:
- P. =?1,? q. =?3,? F (p,? q)? =?10.
- P. =?2,? q. =?3,? F (p,? q)? =?20.
- P. =?4,? q. =?3,? F (p,? q)? =?30.
- P. =?1,? q. =?2,? F (p,? q)? =?10.
- P. =?2,? q. =?4,? F (p,? q)? =?20.
- P. =?4,? q. =?1,? F (p,? q)? =?10.
Another 6 cases is symmetrical to the above. The average is.
Con Sider the second sample. There Are 6 possible situations:
Another 3 cases is symmetrical to the above. The average is.
Test instructions: RT
Idea: Sort the points in descending order first, then a single point to traverse
Assuming that the current point is I, you only need to consider I and the previously traversed points, if there is a point J and the Point V is not the same connected component (can be used and check set)
and J and V can reach I, then f (j,v) must be equal to the weight of I, done after I added and check set can be, and the collection also need to maintain the size of the set
Codeforces Round #250 (Div. 1) B (sort + and check set)