Advertisement
AshfaqFardin

Degree of Nodes Graph (Undirected)

Aug 17th, 2021
1,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.     int total_node, total_edge;
  9.     cin>>total_node>>total_edge;
  10.     vector<int> edges[total_node];
  11.  
  12.     int a,b;
  13.     for(int i=0; i<total_edge; i++)
  14.     {
  15.         cin>>a>>b;
  16.         edges[a].push_back(b);
  17.         edges[b].push_back(a);
  18.     }
  19.  
  20.     for(int i=0;i<total_node;i++) {
  21.         cout<< "adjacency list for "<<i<<endl;
  22.         for(int j=0; j<edges[i].size(); j++) {
  23.             cout<<edges[i][j]<< " ";
  24.         }
  25.         cout<<endl;
  26.     }
  27.    
  28.     for(int i=0;i<total_node;i++) {
  29.         cout << "Degree of "<<i<<endl;
  30.         cout <<edges[i].size() << endl;
  31.     }
  32.    
  33.    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement