Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int vertex, edges;
- cin>>vertex>>edges;
- // declaring adjacency matrix
- int adjMatrix[vertex][vertex]= {{0,0}};
- //Taking input and making the cells which corresponds to the edges as 1 in the adjacency matrix
- for(int i=0; i<edges; i++){
- int vertex1,vertex2;
- cin>> vertex1 >> vertex2;
- adjMatrix[vertex1-1][vertex2-1] = 1;
- adjMatrix[vertex2-1][vertex1-1] = 1;
- }
- // Getting output
- for(int i=0; i<vertex; i++){
- for(int j=0; j<vertex; j++){
- cout<<adjMatrix[i][j]<<" ";
- }
- cout<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement