Advertisement
BowserFlash13

ddas

May 29th, 2020
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4. #include <iterator>
  5. #include <array>
  6. #include <limits.h>
  7.  
  8. #define V 10
  9.  
  10. using namespace std;
  11.  
  12. void stvoriGraf(list<int> adj[], int nVertex)
  13. {
  14.     for (int i = 0; i < nVertex; i++) {
  15.         for (int j = 0; j < nVertex; j++) {
  16.             int create_edge = rand() % 2;
  17.             if (create_edge == 1 && i != j)
  18.                 adj[i].push_back(j);
  19.         }
  20.     }
  21. }
  22.  
  23. void DFS(list<int> adj[], int nVertex, int v, bool visited[])
  24. {
  25.     visited[v] = true;
  26.     //cout << v << " ";
  27.     list<int>::iterator i;
  28.     for (i = adj[v].begin(); i != adj[v].end(); ++i)
  29.         if (!visited[*i])
  30.             DFS(adj, V, *i, visited);
  31. }
  32.  
  33. bool jespojen(list<int> adj[])
  34. {
  35.     bool visited[V];
  36.     for (int i = 0; i < V; i++)
  37.         visited[i] = false;
  38.     DFS(adj, V, 0, visited);
  39.     for (int i = 0; i < V; i++)
  40.         if (visited[i] == false)
  41.             return false;
  42.  
  43.     //Graph gr = getTranspose();
  44.  
  45.     for (int i = 0; i < V; i++)
  46.         visited[i] = false;
  47.  
  48.     //gr.DFSUtil(0, visited);
  49.  
  50.     for (int i = 0; i < V; i++)
  51.         if (visited[i] == false)
  52.             return false;
  53.  
  54.     return true;
  55. }
  56.  
  57.  
  58. int main()
  59. {
  60.     list<int> adj[V];
  61.     stvoriGraf(adj, V);
  62.     if (jespojen(adj) == 0) {
  63.         cout << "Graf nije potpuno spojen";
  64.     }
  65.     else {
  66.         cout << "Graf je potpuno spojen";
  67.     }
  68.    
  69.  
  70.    
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement