Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int a,pomoc,akt;
- int t[1000000];
- int w[1000000];
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin>>a;
- for(int i=1; i<=a; i++)
- {
- cin>>t[i];
- }
- for(int i=1; i<=a; i++)
- {
- if(w[i]!=1)
- {
- int akt=i;
- while(w[i]!=1)
- {
- w[t[akt]]=1;
- akt=t[akt];
- }
- pomoc++;
- }
- }
- cout<<pomoc<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement