Advertisement
Guest User

Untitled

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