Advertisement
amrin26

Graph 2

Feb 17th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int ne;
  7.     cin>>ne;
  8.     int arr[8+1];
  9.     int adj[8+1][8+1];
  10.  
  11.     for(int r=0; r<=8; r++)
  12.     {
  13.         for(int c=0; c<=8; c++)
  14.         {
  15.             adj[r][c] = 0;
  16.         }
  17.  
  18.     }
  19.     for(int i=0; i<=8; i++)
  20.     {
  21.         arr[i]=0;
  22.     }
  23.     for(int i=1; i<=ne; i++)
  24.     {
  25.         int u,v;
  26.         cin>>u>>v;
  27.         adj[u][v]=1;
  28.         adj[v][u]=1;
  29.         arr[u]=1;
  30.         arr[v]=1;
  31.     }
  32.  
  33.     for(int r=0; r<=8; r++)
  34.     {
  35.         for(int c=0; c<=8; c++)
  36.         {
  37.             if(arr[r]!=0 && arr[c]!=0)
  38.                 cout<<adj[r][c] <<" ";
  39.         }
  40.         arr[r]!=0;
  41.         cout<<endl;
  42.     }
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement