Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <iostream>
- #include <queue>
- #include <cstring>
- using namespace std;
- int main()
- {
- int n;
- cin>>n;
- vector<int>v[n];
- int v2[n];
- memset(v2, 0, sizeof v2);
- int max_=-1e9;
- for(int i=0; i<n; i++){
- int a;
- cin>>a;
- a--;
- v[i].push_back(a);
- }
- queue<int>q;
- bool f[n];
- memset(f, false, sizeof f);
- int cekori=0;
- for(int i=0; i<n; i++){
- int s=i;
- if(v2[s]==0){
- memset(f, false, sizeof f);
- v2[s]=1;
- if(cekori>max_){
- max_=cekori;
- }
- cekori=1;
- f[s] = true;
- q.push(s);
- while(!q.empty()){
- int cs=q.front();
- q.pop();
- for(int j=0; j<v[cs].size(); j++){
- int sosed=v[cs][j];
- if(f[sosed]==false){
- f[sosed]=true;
- v2[sosed]=1;
- q.push(sosed);
- cekori++;
- }
- }
- }
- }
- }
- cout<<max(max_, cekori);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement