#include #define I int #define S(a)scanf("%d",&a); #define R for(I i=0;i<(N);i++) #define f(i)A[i]*A[i]/P[i] I N,A[1<<17],V[1<<17],u,v,g;double P[1<<17],E=0;I Z(I a){return V[a]+1?V[a]=Z(V[a]):a;}I U(I a,I b){a=Z(a);b=Z(b);return a^b?V[b]=a:-1;}I main(){S(N)R S(A[i])R{S(u)A[i]-=u;V[i]=-1;}R{S(u)P[i]=1./u;E+=f(i);}S(N)R{S(u)S(v)u=Z(u-1);v=Z(v-1);if(u^v){g=U(u,v);E-=f(u)+f(v);A[g]+=A[u+=v-g];P[g]+=P[u];E+=f(g);}printf("%f\n",E);}return 0;}