Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. ifstream fin("inaltime.in");
  5. ofstream fout("inaltime.out");
  6. int a[105][105], n, k, viz[105], c[105], niv[105], t[105];
  7.  
  8. void citire()
  9. {
  10. int f, g;
  11. fin >> n >> k;
  12. for (int i = 1; i < n; ++i)
  13. {
  14. fin >> f >> g;
  15. a[f][g] = a[g][f] = 1;
  16. }
  17. }
  18.  
  19. void bf(int x)
  20. {
  21. int p,u,k;
  22. p=u=1;
  23. c[p]=x;
  24. viz[x]=1;
  25. niv[x]=1;
  26. while(p<=u)
  27. {
  28. k=c[p];
  29. p++;
  30. for(int i=1; i<=n; ++i)
  31. {
  32. if(t[i]==k && viz[i]==0)
  33. {
  34. u++;
  35. c[u]=i;
  36. viz[i]=1;
  37. niv[i]=niv[k]+1;
  38. //t[i]=k;
  39. }
  40. }
  41. }
  42. }
  43.  
  44. int main()
  45. {
  46. fin>>n;int radacina,maxi=-1;
  47. for(int i=1; i<=n; ++i)
  48. {
  49. fin>>t[i];
  50. if(t[i]==0)
  51. radacina = i;
  52. }
  53. bf(radacina);
  54. for(int i=1; i<=n; ++i)
  55. {
  56. if(niv[i]>maxi)
  57. maxi=niv[i];
  58. }
  59. fout<<maxi;
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement