/* -*- coding: utf-8 -*- * * 3650.cc: No.3650 Teleportation Cycles - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ /* global variables */ int as[MAX_N], gs[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--; fill(gs, gs + n, -1); int gn = 0, lp = 0; for (int st = 0; st < n; st++) if (gs[st] < 0) { int id = gn++, u = st; while (gs[u] < 0) gs[u] = id, u = as[u]; if (gs[u] == id) lp++; } printf("%d\n", lp); return 0; }