func_code_string: #include <bits/stdc++.h>   using namespace std;   using int64 = long long;   using ld = double;   const int MAXN = 1e5 + 1;   vector<int> G[MAXN], comp[MAXN], suf_freq[MAXN];   vector<int64> suf_sum[MAXN];   int comp_cnt, comp_ind[MAXN], p[MAXN], dp1[MAXN], dp2[MAXN], dp[MAXN],       diameter[MAXN];   void max_self(int &a, int b) { a = max(a, b); }   void dfs1(int u) {     comp_ind[u] = comp_cnt;     comp[comp_cnt].emplace_back(u);     for (int v : G[u])       if (!comp_ind[v]) {         p[v] = u;         dfs1(v);         if (dp1[u] <= dp1[v] + 1) {           dp2[u] = dp1[u];           dp1[u] = dp1[v] + 1;         } else           max_self(dp2[u], dp1[v] + 1);       }   }   void dfs2(int u, int dist) {     dp[u] = max(dp1[u], dist);     max_self(diameter[comp_cnt], dp[u]);     for (int v : G[u])       if (v != p[u]) {         if (dp1[u] == dp1[v] + 1)           dfs2(v, max(dp2[u], dist) + 1);         else           dfs2(v, max(dp1[u], dist) + 1);       }   }   ld solve(int x, int y) {     if (x == y) return -1;     if (comp[x].size() > comp[y].size()) swap(x, y);     int D = max(diameter[x], diameter[y]);     ld sum = 0;     for (int d = 0; d <= diameter[x]; ++d) {       int64 freq = suf_freq[x][d];       if (d < diameter[x]) freq -= suf_freq[x][d + 1];       if (freq == 0) continue;       int suf = max(0, min(D - d - 1, diameter[y]));       sum += freq * suf_sum[y][suf];       sum += freq * suf_freq[y][suf] * (d + 1);       int rest = comp[y].size() - suf_freq[y][suf];       sum += freq * rest * D;     }     return sum / ((ld)comp[x].size() * comp[y].size());   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int N, M, Q;     cin >> N >> M >> Q;     for (int i = 0; i < M; ++i) {       int u, v;       cin >> u >> v;       G[u].emplace_back(v);       G[v].emplace_back(u);     }     for (int u = 1; u <= N; ++u)       if (!comp_ind[u]) {         ++comp_cnt;         dfs1(u);         dfs2(u, 0);         suf_sum[comp_cnt] = vector<int64>(diameter[comp_cnt] + 1);         suf_freq[comp_cnt] = vector<int>(diameter[comp_cnt] + 1);         for (int v : comp[comp_cnt]) {           suf_sum[comp_cnt][dp[v]] += dp[v];           ++suf_freq[comp_cnt][dp[v]];         }         for (int d = diameter[comp_cnt] - 1; d >= 0; --d) {           suf_sum[comp_cnt][d] += suf_sum[comp_cnt][d + 1];           suf_freq[comp_cnt][d] += suf_freq[comp_cnt][d + 1];         }       }     map<pair<int, int>, ld> sol;     cout << fixed << setprecision(8);     for (int q = 0; q < Q; ++q) {       int u, v;       cin >> u >> v;       u = comp_ind[u], v = comp_ind[v];       pair<int, int> p{u, v};       auto it = sol.find(p);       if (it != sol.end())         cout << it->second <<   n ;       else {         ld ans = solve(u, v);         sol[p] = sol[make_pair(v, u)] = ans;         cout << ans <<   n ;       }     }     return 0;   }   