Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4. ifstream fin ("nivele.in");
  5. ofstream fout ("nivele.out");
  6. int t[101],n,k,x,niv;
  7. int main()
  8. {
  9. int i,x,y;
  10. fin>>n;
  11. for (i=1;i<=n;i++)
  12. fin>>t[i];
  13. fin>>k;
  14. for (i=1;i<=k;i++)
  15. {
  16. fin>>x;
  17. niv=1;
  18. while (t[x]!=0)
  19. {
  20. niv++;
  21. x=t[x];
  22. }
  23. fout<<niv<<endl;
  24. }
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement