func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   vector<int> G[MAXN + 5];   int maxFrom[MAXN + 5], down[MAXN + 5], up[MAXN + 5];   int id[MAXN + 5], sz[MAXN + 5], diam[MAXN + 5];   bool flag[MAXN + 5];   int ID;   int n, m, Q;   map<int, int> cnt;   vector<int> accSum[MAXN + 5];   vector<double> accWeightedSum[MAXN + 5];   vector<int> vals[MAXN + 5];   map<pair<int, int>, double> oldAns;   void dfs(int u, int p = -1) {     id[u] = ID;     sz[ID]++;     down[u] = 0;     flag[u] = 1;     for (int v : G[u]) {       if (v == p) continue;       dfs(v, u);       down[u] = max(down[u], 1 + down[v]);     }   }   void dfs2(int u, int p = -1, int parentWithoutme = 0) {     if (~p)       up[u] = 1 + parentWithoutme;     else       up[u] = 0;     maxFrom[u] = max(up[u], down[u]);     diam[ID] = max(diam[ID], maxFrom[u]);     cnt[maxFrom[u]]++;     vector<int> paths = {up[u], 0};     for (int v : G[u]) {       if (v == p) continue;       paths[1] = max(paths[1], 1 + down[v]);       if (paths[0] < paths[1]) swap(paths[0], paths[1]);     }     for (int v : G[u]) {       if (v == p) continue;       dfs2(v, u, ((paths[0] != (1 + down[v])) ? paths[0] : paths[1]));     }   }   void calc(int u) {     cnt.clear();     ID = u;     dfs(u);     dfs2(u);     accSum[ID].resize(cnt.size() + 1);     accWeightedSum[ID].resize(cnt.size() + 1);     accSum[ID][0] = 0;     accWeightedSum[ID][0] = 0;     int i = 0;     for (auto p : cnt) {       vals[ID].push_back(p.first);       accSum[ID][i + 1] = accSum[ID][i] + p.second;       accWeightedSum[ID][i + 1] =           accWeightedSum[ID][i] + p.first * (1. * p.second / sz[ID]);       i++;     }   }   int main() {     int c, c2;     scanf( %d%d%d , &n, &m, &Q);     for (c = 0; c < m; c++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       G[u].push_back(v);       G[v].push_back(u);     }     for (c = 0; c < n; c++) {       if (flag[c]) continue;       calc(c);     }     for (c = 0; c < Q; c++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       if (id[u] == id[v])         printf( -1 n );       else {         if (id[u] > id[v]) swap(u, v);         if (oldAns.count({id[u], id[v]}) > 0) {           printf( %.9f n , oldAns[{id[u], id[v]}]);         } else {           if (sz[id[u]] > sz[id[v]]) swap(u, v);           int minDiam = max(diam[id[u]], diam[id[v]]);           double ret = 0;           int j = 0;           for (int x : vals[id[u]]) {             int i =                 lower_bound(vals[id[v]].begin(), vals[id[v]].end(), minDiam - x) -                 vals[id[v]].begin();             double f = 1. * (accSum[id[u]][j + 1] - accSum[id[u]][j]) / sz[id[u]];             ret += f * (accWeightedSum[id[v]].back() - accWeightedSum[id[v]][i] +                         (x + 1.0) * (sz[id[v]] - accSum[id[v]][i]) / sz[id[v]]);             ret += f * (1. * accSum[id[v]][i] / sz[id[v]]) * minDiam;             j++;           }           if (id[u] > id[v]) swap(u, v);           oldAns[{id[u], id[v]}] = ret;           printf( %.9f n , ret);         }       }     }     return 0;   }   