Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int a[100][100], n, m;
  5. int viz[100], queue[100], v[100], pr, ul, este_complet;
  6.  
  7. //Parcurgerile esentiale
  8. void BFS(int nod) {
  9. int x;
  10. viz[nod] = 1;
  11. pr = 0;
  12. ul = -1;
  13. queue[++ul] = nod;
  14. while (pr <= ul) {
  15. for (int i = 1; i <= n; i++) {
  16. x = queue[ul];
  17. if (a[x][i] == 1 && viz[i] == 0) {
  18. queue[++ul] = i;
  19. if (viz[x] == 1) viz[i] = 2;
  20. else viz[i] = 1;
  21. }
  22. }
  23. pr++;
  24. }
  25. }
  26.  
  27. void DFS(int nod) {
  28. v[nod] = 1;
  29. for (int i = 1; i <= n; i++)
  30. if (v[i] == 0 && a[nod][i] == 1)
  31. DFS(i);
  32. }
  33.  
  34. //Functii extra
  35.  
  36. void Vizitare() {
  37. for (int i = 1; i <= n; i++)
  38. v[i] = 0;
  39. }
  40.  
  41. int Bipartit() {
  42. for (int i = 1; i < n; i++)
  43. for (int j = i + 1; j <= n; j++)
  44. if (viz[i] == viz[j])
  45. if (a[i][j] == 1)
  46. return 0;
  47. return 1;
  48. }
  49.  
  50. void verificareBipartit()
  51. {
  52. if (Bipartit() == 1)
  53. cout << "Bipartit";
  54. else cout << "NU";
  55. }
  56.  
  57. int Conex(int v[]) {
  58. for (int i = 1; i <= n; i++)
  59. if (v[i] != 1) return 0;
  60. return 1;
  61. }
  62.  
  63. void verificareConex(int v[])
  64. {
  65. if (Conex(v) == 1)
  66. cout << "Graf conex";
  67. else
  68. cout << "Nu este conex";
  69. }
  70.  
  71. int existaNodNev() {
  72. for (int i = 1; i <= n; i++)
  73. if (viz[i] == 0)
  74. return i;
  75. return 0;
  76. }
  77.  
  78. void complet()
  79. {
  80. for (int i = 1; i <= n; i++) {
  81. for (int j = 1; j <= n; j++) {
  82. if (a[i][j] == 0 && i != j) {
  83. este_complet = 0;
  84. break;
  85. }
  86. }
  87. if (este_complet == 0) {
  88. break;
  89. }
  90. }
  91. if (este_complet == 1) {
  92. cout << "Graful este complet. ";
  93. }
  94. else {
  95. cout << "Graful este incomplet. ";
  96. }
  97. }
  98.  
  99. int main() {
  100. int x, y;
  101. cout << "Scrie numarul de varfuri: ";
  102. cin >> n;
  103. cout << "Scrie numarul de muchii: ";
  104. cin >> m;
  105. for (int i = 1; i <= m; i++) {
  106. cout << "Scrie extremitatile muchiei " << i << ": ";
  107. cin >> x >> y;
  108. a[x][y] = 1;
  109. a[y][x] = 1;
  110. }
  111. complet();
  112. }
  113.  
  114. /*
  115. exemplu graf bipartit
  116. 7
  117. 7
  118. 1 2
  119. 1 3
  120. 1 5
  121. 2 4
  122. 3 7
  123. 4 6
  124. 6 7
  125. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement