func_code_string: #include <bits/stdc++.h>   using namespace std;   int get_set(int v, vector<int>& parent) {     if (v != parent[v]) {       parent[v] = get_set(parent[v], parent);     }     return parent[v];   }   void union_set(int a, int b, vector<int>& parent, vector<int>& rang) {     a = get_set(a, parent);     b = get_set(b, parent);     if (a != b) {       if (rang[a] < rang[b]) {         swap(a, b);       }       parent[b] = a;       rang[a] += rang[b];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, a, s = 0, k, p, l, r;     cin >> n >> m;     vector<map<int, int>> x(n), y(m);     vector<int> parent(n * m), rang(n * m, 0);     vector<pair<int, int>> q(n * m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> a;         q[s] = make_pair(a, s);         parent[s] = s;         rang[s] = 1;         if (x[i].count(a) != 0) {           union_set(s, i * m + x[i][a], parent, rang);         }         if (y[j].count(a) != 0) {           union_set(s, y[j][a] * m + j, parent, rang);         }         x[i][a] = j;         y[j][a] = i;         s++;       }     for (int i = 0; i < n * m; i++) rang[i] = 0;     sort(begin(q), end(q));     for (int i = 0; i < n * m; i++) {       a = q[i].first;       s = q[i].second;       l = s / m;       r = s % m;       swap(q[i].first, q[i].second);       k = get_set(s, parent);       k = rang[k];       auto j = x[l].find(a);       j++;       if (j != end(x[l])) {         p = get_set(l * m + j->second, parent);         rang[p] = max(k + 1, rang[p]);       }       j = y[r].find(a);       j++;       if (j != end(y[r])) {         p = get_set(j->second * m + r, parent);         rang[p] = max(k + 1, rang[p]);       }     }     sort(begin(q), end(q));     for (int i = 0; i < n * m; i++) {       k = get_set(q[i].first, parent);       k = rang[k];       cout << k + 1 <<    ;       if ((q[i].first + 1) % m == 0) cout << endl;     }     return 0;   }   