#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; using ull = unsigned long long; 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; } //template T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; } //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353; class UnionFind { public: vector Parent; UnionFind(int N) { Parent = vector(N, -1); } int root(int A) { if (Parent[A] < 0) { return A; } return Parent[A] = root(Parent[A]); } long long size(int A) { return -(long long)Parent[root(A)]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) { return false; } if (size(A) < size(B)) { swap(A, B); } Parent[A] += Parent[B]; Parent[B] = A; return true; } bool same(int A, int B) { return root(A) == root(B); } }; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); using Real = double; int n; cin >> n; vector a(n); for (auto& e : a) cin >> e; vector b(n); for (auto& e : b) cin >> e; vector p(n); for (auto& e : p) cin >> e; UnionFind uf(n); vector res(n); vector rp(n); vector pn(n); auto f = [&](Real x, Real y) {return (x - y) * (x - y); }; for (int i = 0; i < n; i++) res[i] = (double)p[i] * f(a[i], b[i]), rp[i] = 1.0 / (Real)p[i], pn[i] += a[i] - b[i]; int kkt; cin >> kkt; Real pre = 0; for (int i = 0; i < n; i++) pre += res[i]; while (kkt--) { int u, v; cin >> u >> v; u--; v--; u = uf.root(u); v = uf.root(v); if (uf.same(u, v)) { cout << fixed << setprecision(15) << pre << "\n"; } else { Real ans = pre - res[u] - res[v]; vector cn(101); Real p = abs(pn[u] + pn[v]); Real t = pn[u] + pn[v]; Real ch = 0; if (cn[0] > 0) { cout << fixed << setprecision(15) << ans << "\n"; pre = ans; } else { ch = p * p / (rp[u] + rp[v]); ans += ch; cout << fixed << setprecision(15) << ans << "\n"; pre = ans; } uf.connect(u, v); int root = uf.root(u); res[root] = ch; rp[root] = rp[u] + rp[v]; pn[root] = t; } } }