func_code_string: #include <bits/stdc++.h>   using namespace std;   void dfs(const vector<int> &next, vector<bool> &visited, vector<int> &end,            int x) {     visited[x] = true;     int y = next[x];     if (!visited[y]) {       dfs(next, visited, end, y);       end[x] = end[y];     } else       end[x] = x;   }   int main() {     int n;     scanf( %d , &n);     vector<int> next(n), deg(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &next[i]);       --next[i];       ++deg[next[i]];     }     vector<int> start, end, g_end(n, -1);     vector<bool> visited(n, false);     for (int i = 0; i < n; ++i)       if (deg[i] == 0) {         start.push_back(i);         dfs(next, visited, g_end, i);         end.push_back(g_end[i]);       }     for (int i = 0; i < n; ++i)       if (!visited[i]) {         start.push_back(i);         dfs(next, visited, g_end, i);         end.push_back(g_end[i]);       }     int cnt = int(start.size());     if (cnt == 1 && deg[start[0]] > 0)       printf( 0 n );     else {       printf( %d n , cnt);       for (int i = 0; i < cnt; ++i)         printf( %d %d n , end[i] + 1, start[(i + 1) % cnt] + 1);     }     return 0;   }   