#include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; struct UnionFind { vector data; UnionFind(int size) : data(size, -1) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector a(n), b(n), p(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; for(int i = 0; i < n; i++) cin >> p[i]; UnionFind uf(n); vector sum_ratio(n), sum_val(n); vector sum_ene(n); long double ans = 0.0; for(int i = 0; i < n; i++){ sum_ratio[i] = (long double)1.0/(long double)p[i]; sum_ene[i] = (a[i]-b[i]); sum_val[i] = p[i]*(a[i]-b[i])*(a[i]-b[i]); ans += sum_val[i]; } int q; cin >> q; for(int i = 0; i < q; i++){ int x, y; cin >> x >> y; x--; y--; if(!uf.findSet(x, y)){ int xr = uf.root(x), yr = uf.root(y); long double sr = sum_ratio[xr]+sum_ratio[yr]; int se = sum_ene[xr]+sum_ene[yr]; long double sv = (long double)(se*se)/sr; ans += sv-sum_val[xr]-sum_val[yr]; uf.unionSet(x, y); int r = uf.root(x); sum_ene[r] = se; sum_val[r] = sv; sum_ratio[r] = sr; // cout << se << ' ' << sr << ' ' << sv << endl; } cout << (ans < 0.0 ? 0.0 : ans) << endl; } }