class UnionFind: def __init__(self, n): self.parent = list(range(n)) #親ノード self.size = [1]*n #グループの要素数 def root(self, x): #root(x): xの根ノードを返す. while self.parent[x] != x: self.parent[x] = self.parent[self.parent[x]] x = self.parent[x] return x def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる x, y = self.root(x), self.root(y) if x == y: return False if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように self.size[x] += self.size[y] #xの要素数を更新 self.parent[y] = x #yをxにつなぐ return True def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue return self.root(x) == self.root(y) def getsize(self,x): #size(x): xのいるグループの要素数を返す return self.size[self.root(x)] n = int(input()) *a, = map(int,input().split()) *b, = map(int,input().split()) *p, = map(float,input().split()) d = [ai-bi for ai,bi in zip(a,b)] UF = UnionFind(n) q = int(input()) ans = sum(pi*di**2 for pi,di in zip(p,d)) eps = 1e-9 for _ in range(q): x,y = map(int,input().split()) x -= 1; y -= 1 rx,ry = UF.root(x), UF.root(y) if rx != ry: ans -= p[rx]*d[rx]**2 + p[ry]*d[ry]**2 UF.merge(rx,ry) nr = UF.root(rx) if abs(p[rx]) < eps and abs(p[ry]) < eps: p[nr] = 0 else: p[nr] = 1/(1/p[rx]+1/p[ry]) d[nr] = d[rx]+d[ry] ans += p[nr]*d[nr]**2 print(ans)