Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
4,007 views
in Online Assessments by Expert (108,100 points) | 4,007 views

2 Answers

1 like 0 dislike

This should be the answer of this question.

Correct me if I am wrong.  

 

  ll n;
    cin>>n;
    
    vector<int> v(n+1);
    for(int i=1; i<=n; i++){
        cin>>v[i];
    }
    map<int,int> mp;    ll ans=0;

    for(int i=1; i<=n; i++){
        mp[v[v[v[i]]]]++;
        // ans=max(ans,mp[v[v[v[i]]]]);
    }
    for(auto it: mp){
        ll x=it.ss;
        ans+=(x)*(x-1)/2;
    }

    cout<<ans<<'\n';

by (160 points)
what is it.ss means
0 like 1 dislike

Question Description.

by Expert (108,100 points)

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .