Advertisement
hopingsteam

Untitled

Mar 15th, 2020
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("fisier.in");
  7.  
  8. int n, levelMax, tLevelMax;
  9. int mat[105][105];
  10.  
  11. bool subpcta()
  12. {
  13. //subpct i
  14. int contor = 0;
  15. for(int p = 2; p <= n; p++)
  16. {
  17. for(int i = 1; i < p; p++)
  18. {
  19. if(mat[i][p])
  20. contor++;
  21. if(mat[p][i])
  22. contor++;
  23. }
  24. if(mat[p][p])
  25. contor++;
  26.  
  27. if(contor != 2 * p - 2)
  28. return false;
  29. }
  30.  
  31. //subpct ii
  32. for(int i = 1; i <= n; i++)
  33. {
  34. for(int j = 1; j <= i; j++)
  35. {
  36. if(!((mat[i][j] == 0 && mat[j][i] == 0) || (mat[i][j] == mat[j][i] + 1)))
  37. return false;
  38. }
  39. }
  40.  
  41. //subpct iii
  42. for(int i = 1; i <= n; i++)
  43. {
  44. int el = 0;
  45. for(int j = 1; j <= n; j++)
  46. {
  47. if(mat[i][j] != 0 && el == 0)
  48. el = mat[i][j];
  49. if(mat[i][j] != 0 && el != 0 && mat[i][j] != el)
  50. return false;
  51. }
  52. }
  53. }
  54.  
  55. int tt[105];
  56.  
  57. void DFS(int Nod, int T, int level)
  58. {
  59. tt[Nod] = T;
  60. if(levelMax < level)
  61. {
  62. levelMax = level;
  63. tLevelMax = Nod;
  64. }
  65. for(int i = 1; i <= n; i++)
  66. {
  67. if(mat[Nod][i] != 0 && tt[i] == 0)
  68. {
  69. DFS(i, Nod, level + 1);
  70. }
  71. }
  72. }
  73.  
  74. int main()
  75. {
  76. fin >> n;
  77. for(int i = 1; i <= n; i++)
  78. {
  79. for(int j = 1; j <= n; j++)
  80. {
  81. fin >> mat[i][j];
  82. }
  83. }
  84.  
  85. DFS(1, -1, 1);
  86. while(tLevelMax != -1)
  87. {
  88. cout << tLevelMax << " ";
  89. tLevelMax = tt[tLevelMax];
  90. }
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement