Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- ifstream fin ("inaltime.in");
- ofstream fout ("inaltime.out");
- int n, k, v[101], tata[101], i, j;
- int main()
- {
- int radacina, contor;
- fin >> n;
- for (int i=1; i<=n; i++)
- {
- fin >> tata[i];
- if (!tata[i])
- radacina=i;
- }
- int H=0;
- for (int i=1; i<=n; i++)
- {
- contor=1;
- j=i;
- while (j!=radacina)
- {
- contor ++;
- j=tata[j];
- }
- if (contor> H)
- H=contor;
- }
- fout << H;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement