Advertisement
a53

NivelePare

a53
May 15th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("nivelepare.in");
  4. ofstream fout("nivelepare.out");
  5.  
  6. int n,T[101],r,D[101],Q[101],nmax;
  7.  
  8. void DF(int x)
  9. {
  10. for(int i=1; i<=n; i++)
  11. if(T[i]==x)
  12. {
  13. D[i]=D[x]+1;
  14. DF(i);
  15. }
  16. }
  17.  
  18. int main()
  19. {
  20. fin>>n;
  21. for(int i=1; i<=n; i++)
  22. {
  23. fin>>T[i];
  24. if(T[i]==0)
  25. r=i;
  26. }
  27. DF(r);
  28. for(int i=1; i<=n; i++)
  29. if(D[i]>nmax)
  30. nmax=D[i];
  31. for(int i=0; i<=nmax; i++)
  32. {
  33. if(i%2==0)
  34. {
  35. for(int j=1; j<=n; j++)
  36. if(D[j]==i)
  37. fout<<j<<" ";
  38. fout<<'\n';
  39. }
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement