Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. using namespace std;
  5. ifstream f("inaltime.in");
  6. ofstream g("inaltime.out");
  7. int p,i,n,v[1001],q,maxx;
  8. int main()
  9. {
  10. f>>n;
  11. for(i=1; i<=n; i++)
  12. {
  13. f>>p;
  14. v[i]=p;
  15. }
  16. for(i=1; i<=n; i++)
  17. {
  18. q=1;
  19. p=i;
  20. while(v[p]!=0)
  21. {
  22. q++;
  23. p=v[p];
  24. }
  25. if(q>maxx)
  26. maxx=q;
  27. }
  28. g<<maxx;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement