Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream fin("inaltime.in");
  6. ofstream fout("inaltime.out");
  7.  
  8. int tata[105],n,i,viz[105],H=0,k,h;
  9.  
  10. int main()
  11. {
  12. fin>>n;
  13. for(i=1;i<=n;i++)
  14. fin>>tata[i];
  15. for(i=1;i<=n;i++)
  16. {
  17. k=i;h=1;
  18. while(tata[k]!=0)
  19. {
  20. k=tata[k];h++;
  21. }
  22. if(h>H)H=h;
  23. }
  24. fout<<H;
  25.  
  26.  
  27.  
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement