func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, k, w, f[1005], ans, cnt, t;   char a[1005][15][15];   vector<int> v[1005];   struct rec {     int x, y, z;   } e[1050005];   bool operator<(rec a, rec b) { return (a.z < b.z); }   int find(int x) {     if (f[x] == x)       return x;     else       return (f[x] = find(f[x]));   }   void dfs(int x, int fa) {     if (x > 0) cout << x <<     << fa <<   n ;     for (auto y : v[x])       if (y != fa) dfs(y, x);   }   int main() {     cin >> n >> m >> k >> w;     for (int i = 1; i <= k; ++i) {       for (int j = 1; j <= n; ++j)         for (int k = 1; k <= m; ++k) cin >> a[i][j][k];       e[++cnt].x = 0, e[cnt].y = i, e[cnt].z = n * m;       for (int j = 1; j <= i - 1; ++j) {         int sum = 0;         for (int k = 1; k <= n; ++k)           for (int l = 1; l <= m; ++l)             if (a[j][k][l] != a[i][k][l]) sum += w;         e[++cnt].x = i, e[cnt].y = j, e[cnt].z = sum;       }     }     sort(e + 1, e + cnt + 1);     for (int i = 0; i <= k; ++i) f[i] = i;     for (int i = 1; i <= cnt; ++i) {       int p = find(e[i].x), q = find(e[i].y);       if (p != q) {         f[p] = q;         ans += e[i].z;         v[e[i].x].push_back(e[i].y), v[e[i].y].push_back(e[i].x);         ++t;         if (t == k) break;       }     }     cout << ans <<   n ;     dfs(0, -1);     return 0;   }   