# APCS ### 20170304-2 ```cpp= #include<bits/stdc++.h> #define ll long long #define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) using namespace std; signed main(){ fastio; vector<ll> tracked, homie; ll n, x, y, sum; while(cin>>n){ homie.assign(n+1,0); tracked.assign(n+1,0); sum=0; for(x=0;x<n;x++){ cin>>homie[x]; } for(x=0;x<n;x++){ if(tracked[x]){ continue; } y=homie[x]; while(y!=x){ tracked[y]=1; y=homie[y]; } sum++; } cout<<sum<<'\n'; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up