Advertisement
Rakibul_Ahasan

Adjacency matrix

Nov 11th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1.  #include <iostream>
  2.  
  3.     using namespace std;
  4.  
  5.     bool A[10][10];
  6.  
  7.     void initialize()
  8.     {
  9.         for(int i = 0;i < 10;++i)
  10.             for(int j = 0;j < 10;++j)
  11.                 A[i][j] = false;
  12.     }
  13.  
  14.     int main()
  15.     {
  16.         int x, y, nodes, edges;
  17.         initialize();       //Since there is no edge initially
  18.         cin >> nodes;       //Number of nodes
  19.         cin >> edges;       //Number of edges
  20.         for(int i = 0;i < edges;++i)
  21.         {
  22.             cin >> x >> y;
  23.             A[x][y] = true;     //Mark the edges from vertex x to vertex y
  24.        }
  25.        if(A[3][4] == true)
  26.           cout << "There is an edge between 3 and 4" << endl;
  27.       else
  28.           cout << "There is no edge between 3 and 4" << endl;
  29.  
  30.       if(A[2][3] == true)
  31.           cout << "There is an edge between 2 and 3" << endl;
  32.       else
  33.           cout << "There is no edge between 2 and 3" << endl;
  34.  
  35.       return 0;
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement