func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int pre[N], rak[N];   int find(int first) {     if (pre[first] == -1) return first;     return pre[first] = find(pre[first]);   }   void unions(int first, int second) {     first = find(first);     second = find(second);     if (first == second) return;     if (rak[first] < rak[second]) swap(first, second);     rak[first] += rak[second];     pre[second] = first;   }   vector<pair<int, int> > rows[N], col[N];   void scc(int n, int m) {     memset(pre, -1, sizeof(pre));     fill(rak, rak + N, 1);     for (int i = 1; i <= n; i++) {       sort(rows[i].begin(), rows[i].end());       for (int j = 1; j < m; j++) {         if (rows[i][j - 1].first == rows[i][j].first)           unions((i - 1) * m + rows[i][j - 1].second,                  (i - 1) * m + rows[i][j].second);       }     }     for (int j = 1; j <= m; j++) {       sort(col[j].begin(), col[j].end());       for (int i = 1; i < n; i++) {         if (col[j][i - 1].first == col[j][i].first)           unions((col[j][i - 1].second - 1) * m + j,                  (col[j][i].second - 1) * m + j);       }     }   }   vector<int> edges[N];   int deg[N], ans[N];   stack<int> stk;   void topo(int n, int m) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j < m; j++) {         if (rows[i][j - 1].first < rows[i][j].first) {           int first = find((i - 1) * m + rows[i][j - 1].second);           int second = find((i - 1) * m + rows[i][j].second);           edges[first].push_back(second);           deg[second]++;         }       }     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i < n; i++) {         if (col[j][i - 1].first < col[j][i].first) {           int first = find((col[j][i - 1].second - 1) * m + j);           int second = find((col[j][i].second - 1) * m + j);           edges[first].push_back(second);           deg[second]++;         }       }     }     n = n * m;     for (int i = 1; i <= n; i++)       if (!deg[i] && pre[i] == -1) stk.push(i), ans[i] = 1;     while (!stk.empty()) {       int u = stk.top();       stk.pop();       for (int i = 0; i < edges[u].size(); i++) {         int first = edges[u][i];         ans[first] = max(ans[first], ans[u] + 1);         deg[first]--;         if (!deg[first]) stk.push(first);       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1, first; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &first);         rows[i].push_back(make_pair(first, j));         col[j].push_back(make_pair(first, i));       }     }     scc(n, m);     topo(n, m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         printf( %d%c , ans[find((i - 1) * m + j)], (j == m) ?   n  :    );       }     }     return 0;   }   