Advertisement
UvrajSB

code

May 13th, 2022
1,489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int vertex, edges;
  7.     cin>>vertex>>edges;
  8.     // declaring adjacency matrix
  9.     int adjMatrix[vertex][vertex]= {{0,0}};
  10.     //Taking input and making the cells which corresponds to the edges as 1 in the adjacency matrix
  11.     for(int i=0; i<edges; i++){
  12.         int vertex1,vertex2;
  13.         cin>> vertex1 >> vertex2;
  14.         adjMatrix[vertex1-1][vertex2-1] = 1;
  15.         adjMatrix[vertex2-1][vertex1-1] = 1;
  16.     }
  17.     // Getting output
  18.     for(int i=0; i<vertex; i++){
  19.         for(int j=0; j<vertex; j++){
  20.             cout<<adjMatrix[i][j]<<" ";
  21.         }
  22.         cout<<"\n";
  23.     }
  24.    
  25.     return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement