func_code_string: #include <bits/stdc++.h>   using namespace std;   const unsigned long long inf = 0x3f3f3f3f3f3f3f3f;   const unsigned long long MAXN = 1e5 + 5;   unsigned long long cnt[MAXN];   vector<unsigned long long> adj[MAXN];   vector<unsigned long long> vis(MAXN, 0);   void dfs(unsigned long long v) {     vis[v] = 1;     if (adj[v].size() == 1 && v != 1) {       cnt[v] = 1;       return;     }     for (auto u : adj[v]) {       if (!vis[u]) {         dfs(u);         cnt[v] += cnt[u];       }     }     ++cnt[v];   }   unsigned long long nc2(unsigned long long n) {     if (n < 2) return 0;     return (n * (n - 1)) / 2;   }   long double nc3(unsigned long long n) {     if (n < 3) return 0;     return ((long double)n * (n - 1) * (n - 2)) / 6.0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     unsigned long long n;     cin >> n;     pair<pair<unsigned long long, unsigned long long>, unsigned long long> cst[n];     for (unsigned long long i = 0; i < n - 1; i++) {       unsigned long long u, v, l;       cin >> u >> v >> l;       adj[v].push_back(u);       adj[u].push_back(v);       cst[i + 1] = {{u, v}, l};     }     dfs(1);     long double ini = 0;     long double wgt[n];     fill(wgt, wgt + n, 0);     long double ttl = nc3(n);     for (unsigned long long i = 1; i < n; i++) {       unsigned long long u = cst[i].first.first, v = cst[i].first.second;       unsigned long long lft = min(cnt[u], cnt[v]);       unsigned long long rgt = n - lft;       wgt[i] += (long double)lft * nc2(rgt) + rgt * nc2(lft);       wgt[i] *= 2;       wgt[i] /= ttl;       ini += wgt[i] * cst[i].second;     }     unsigned long long q;     cin >> q;     cout << fixed << setprecision(12);     while (q--) {       unsigned long long idx, x;       cin >> idx >> x;       ini -= wgt[idx] * (cst[idx].second - x);       cst[idx].second = x;       long double d = ini;       cout << d <<   n ;     }     return 0;   }   