#include #include using namespace std; using namespace atcoder; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=14449999999999999; ll mod=998244353; struct unionfind { vectorpar,siz; unionfind(ll n): par(n,-1),siz(n,1){} ll root(ll x){ if (par[x]==-1) { return x; }else{ return par[x]=root(par[x]); } } bool issame(ll x,ll y){ return root(x)==root(y); } bool unite(ll x,ll y){ x=root(x); y=root(y); if (x==y) { return false; } if (siz[x]> n; vectorp(n); unionfind uf(n); for (ll i = 0; i < n; i++) { cin >> p[i]; p[i]--; uf.unite(p[i],i); } vectormemo(n,0); ll ans=0; for (ll i = 0; i < n; i++) { if (memo[uf.root(i)]==0) { ans+=1; memo[uf.root(i)]+=1; } } cout << n-ans << endl; }