#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define PII pair<int,int >
#define int long long
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e6+10;
int n;
int acc[N];
int find(int x)
{
if(acc[x]==x) return x;
else return acc[x]=find(acc[x]);
}
signed main()
{
IOS;
cin>>n;
int sum=0;
for(int i=1;i<=n;i++) acc[i]=i;
for(int i=1;i<=n;i++)
{
int x;cin>>x;
acc[find(i)]=find(x);
}
for(int i=1;i<=n;i++)
{
if(acc[i]==i) sum++;
}
cout<<sum;
return 0;
}
SKA-Piggy Banks
于 2024-07-30 12:00:13 首次发布