func_code_string: #include <bits/stdc++.h>   using namespace std;   const int NMAX = 100000;   vector<int> g[NMAX + 1];   int H[NMAX + 1], D[NMAX + 1], G[NMAX + 1], GS[NMAX + 1];   long long DS[NMAX + 1];   vector<int> data[NMAX + 1];   vector<long long> acc[NMAX + 1], psum[NMAX + 1];   int dfs1(int u, int p, int gp) {     G[u] = gp;     GS[gp]++;     for (int v : g[u])       if (v != p) H[u] = max(dfs1(v, u, gp) + 1, H[u]);     return H[u];   }   void dfs2(int u, int p, int pLen = 0) {     int m1 = -2, mi1 = -1, m2 = -2, mi2 = -1;     for (int v : g[u])       if (v != p) {         if (m2 < H[v]) m2 = H[v], mi2 = v;         if (m1 < m2) swap(m1, m2), swap(mi1, mi2);       }     D[u] = max(pLen, m1 + 1);     for (int v : g[u])       if (v != p) {         if (v == mi1)           dfs2(v, u, max(pLen + 1, m2 + 2));         else           dfs2(v, u, max(pLen + 1, m1 + 2));       }     while (data[G[u]].size() <= D[u]) data[G[u]].push_back(0);     data[G[u]][D[u]]++;     DS[G[u]] += D[u];   }   map<pair<int, int>, double> cache;   void query(int u, int v) {     u = G[u], v = G[v];     if (u == v) {       printf( -1 n );       return;     }     if (data[u].size() > data[v].size()) swap(u, v);     pair<int, int> P(u, v);     if (cache.count(P)) {       printf( %.10f n , cache[P]);       return;     }     long long S = 1LL * GS[u] * GS[v] + 1LL * GS[u] * DS[v] + 1LL * DS[u] * GS[v];     int bound = data[v].size() - 1;     for (int i = 0; i < data[u].size(); i++) {       int R = bound - i - 1;       if (0 <= R) {         R = min(R, (int)data[v].size() - 1);         long long terms = data[u][i] * acc[v][R];         S -= i * terms + psum[v][R] * data[u][i] + terms;         S += bound * terms;       }     }     printf( %.10f n , (double)S / GS[u] / GS[v]);   }   void process() {     int N, M, Q;     scanf( %d%d%d , &N, &M, &Q);     for (int i = 0; i < M; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     int gps = 0;     for (int i = 1; i <= N; i++)       if (!G[i]) {         gps++;         dfs1(i, -1, gps);       }     for (int i = 1; i <= N; i++)       if (data[G[i]].empty()) {         dfs2(i, -1);       }     for (int i = 1; i <= gps; i++) {       acc[i] = psum[i] = vector<long long>(data[i].size());       acc[i][0] = data[i][0];       for (int j = 1; j < acc[i].size(); j++)         acc[i][j] = acc[i][j - 1] + data[i][j];       for (int j = 1; j < psum[i].size(); j++)         psum[i][j] = psum[i][j - 1] + 1LL * data[i][j] * j;     }     for (int i = 0; i < Q; i++) {       int u, v;       scanf( %d%d , &u, &v);       query(u, v);     }   }   int main() { process(); }   