#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin>>n;
int a[1001];
for(int i=1;i<=n;i++)
cin>>a[i];
vector<vector<int> > ans;
for(int i=1;i<=n;i++){
if(a[i]!=-1){
int x=ans.size();
ans.push_back(vector<int>());
ans[x].push_back(i);
ans[x].push_back(a[i]);
int j=a[i];
a[i]=-1;
while(j!=i){
ans[x].push_back(a[j]);
int tmp=j;
j=a[j];
a[tmp]=-1;
}
}
}
cout<<ans.size()<<'\n';
for(auto x:ans){
for(auto y:x)
cout<<y<<' ';
cout<<'\n';
}
}
Comments
Post a Comment