import java.util.Arrays; import java.util.Scanner; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] P = new int[N]; Arrays.setAll(P,i->sc.nextInt()); UnionFind uf = new UnionFind(N+1); int ans = 0; for(int i=0;i1) continue; int p = i; while(uf.unite(p,P[p])) p = P[p]; ans += uf.size(i)-1; } System.out.println(ans); } } class UnionFind{ int[] size,par; UnionFind(int N){ size = new int[N]; par = new int[N]; Arrays.fill(size,1); Arrays.fill(par,-1); } boolean unite(int x,int y){ int rootX = root(x); int rootY = root(y); if(rootX==rootY) return false; if(size[y]