func_code_string: #include <bits/stdc++.h>   using namespace std;   int up[200005];   void init() { memset(up, -1, sizeof(up)); }   int Find(int x) {     if (up[x] < 0) return x;     int root = Find(up[x]);     up[x] = root;     return root;   }   void Union(int x, int y) {     x = Find(x);     y = Find(y);     if (x == y) return;     if (up[x] < up[y]) {       up[x] += up[y];       up[y] = x;     } else {       up[y] += up[x];       up[x] = y;     }   }   int n;   int a[200005];   vector<int> can;   set<int> aree;   signed main() {     init();     int x;     scanf( %d , &n);     int keep = -1;     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (Find(x) != Find(i)) {         Union(x, i);         a[i] = x;       } else {         if (x == i && keep == -1) {           keep = 0;           a[i] = x;         } else {           a[i] = -1;           can.push_back(i);         }       }     }     if (keep == -1) {       a[*(can.end() - 1)] = *(can.end() - 1);       can.pop_back();     }     for (int i = 1; i <= n; i++) {       aree.insert(Find(i));     }     for (auto i : can) {       for (set<int>::iterator k = aree.begin(); k != aree.end(); k++) {         int j = *k;         int u, v;         u = Find(j);         v = Find(i);         if (Find(j) != Find(i)) {           a[i] = j;           Union(i, j);           aree.erase(v);           aree.erase(u);           aree.insert(Find(j));           goto lol;         }       }     lol:;     }     cout << can.size() - keep <<   n ;     for (int i = 1; i <= n; i++) {       cout << a[i] <<    ;     }   }   