func_code_string: #include <bits/stdc++.h>   using namespace std;   const int mxn = 1e6 + 3;   struct node {     int v, i, j, id;   } a[mxn];   int n, m, r[mxn], c[mxn], f[mxn], v[mxn], o[mxn];   int cmp(node a, node b) { return a.v < b.v; }   int fffa(int x) { return f[x] == x ? x : f[x] = fffa(f[x]); }   int main() {     scanf( %d%d , &n, &m);     for (int(i) = (int)(1); (i) <= (int)(n); ++(i))       for (int(j) = (int)(1); (j) <= (int)(m); ++(j)) {         int id = (i - 1) * m + j;         scanf( %d , &o[id]);         a[id].v = o[id];         a[id].i = i;         a[id].j = j;         a[id].id = f[id] = id;       }     sort(a + 1, a + 1 + n * m, cmp);     for (int(i) = (int)(1); (i) <= (int)(n * m); ++(i)) {       int fi = fffa(r[a[i].i]);       int fj = fffa(c[a[i].j]);       v[a[i].id] = max(v[fi] + (a[i].v > o[fi]), v[fj] + (a[i].v > o[fj]));       int p = fffa(a[i].id);       if (a[i].v == o[fi]) f[fi] = p;       if (a[i].v == o[fj]) f[fj] = p;       r[a[i].i] = c[a[i].j] = p;     }     for (int(i) = (int)(1); (i) <= (int)(n); ++(i))       for (int(j) = (int)(1); (j) <= (int)(m); ++(j))         printf( %d%c , v[fffa((i - 1) * m + j)],    n [j == m]);     return 0;   }   