func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   pair<int, pair<int, int> > A[maxn];   map<int, int> X;   map<int, int> Y;   int Hx[maxn], Hy[maxn];   int ans[maxn];   int fa[maxn];   int fi(int u) {     if (fa[u] == u) return u;     return fa[u] = fi(fa[u]);   }   void un(int u, int v) {     int p1 = fi(u), p2 = fi(v);     if (p1 != p2) fa[p1] = p2;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n * m; i++) {       fa[i] = i;       scanf( %d , &A[i].first);       A[i].second.first = i / m;       A[i].second.second = i % m;     }     int j = -1;     sort(A, A + n * m);     for (int i = 0; i < n * m; i++) {       if (i != n * m - 1 && A[i].first == A[i + 1].first) continue;       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         Hx[x] = p;         Hy[y] = p;       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         un(Hx[x], p);         un(Hy[y], p);       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         int pa = fi(p);         ans[pa] = max(ans[pa], max(X[x], Y[y]) + 1);       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         X[x] = max(X[x], ans[fi(p)]);         Y[y] = max(Y[y], ans[fi(p)]);       }       j = i;     }     for (int i = 0; i < n * m; i++) {       printf( %d  , ans[fi(i)]);       if (i % m == m - 1) printf(  n );     }   }   