func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n, c[6][223456], child[223456];   double ans[223456], res = 0.0;   vector<pair<int, double> > ke[223456];   pair<pair<int, int>, double> way[223456];   int dad[223456];   void dfs1(int u, int par) {     child[u] = 1;     dad[u] = par;     for (int i = 0; i < ke[u].size(); i++) {       int v = ke[u][i].first;       if (v == par) continue;       dfs1(v, u);       child[u] += child[v];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     int u, v;     double w;     for (int i = 1; i < n; i++) {       cin >> u >> v >> w;       ke[u].push_back(make_pair(v, w));       ke[v].push_back(make_pair(u, w));       way[i] = make_pair(make_pair(u, v), w);     }     dfs1(1, 0);     res = 0;     for (int i = 1; i < n; i++) {       int u1 = way[i].first.first;       int u2 = way[i].first.second;       if (dad[u2] == u1) swap(u1, u2);       double we = way[i].second;       res += we * (child[u1] * (n - child[u1]));     }     int q;     cin >> q;     while (q--) {       cin >> u >> w;       int u1 = way[u].first.first;       int u2 = way[u].first.second;       if (dad[u2] == u1) swap(u1, u2);       double we = way[u].second;       res -= (we - w) * double(child[u1] * (n - child[u1]));       way[u].second = w;       cout << fixed << setprecision(8) << res / double(n * (n - 1) / 6.0) <<   n ;     }     return 0;   }   