Advertisement
aidul23

Implement Adjacency List and find out Indegree and OutDegree of every vertex

Aug 30th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int mx = 1005;
  4. vector < int > adj[mx];
  5. int main()
  6. {
  7.     int n,e,u,v,count;
  8.     cout << "nodes : ";
  9.     cin >> n;
  10.     cout << "edges : ";
  11.     cin >> e;
  12.     cout << "connection\n";
  13.     for(int i=0; i<e; i++)
  14.     {
  15.         cin >> u >> v;
  16.         adj[u].push_back(v);
  17.     }
  18.  
  19.     cout << "All Node's Indegree and Outdegrees are:\n";
  20.     for(int i=1; i<=n; i++)
  21.     {
  22.         cnt = 0;
  23.         cout << "Outegree of " << i << " is : ";
  24.         cout << adj[i].size() << "\t";
  25.         cout << "Indegree of " << i << " is : ";
  26.         for(int j=1; j<=n; j++)
  27.         {
  28.             for(int k=0; k<adj[j].size(); k++)
  29.             {
  30.                 if(adj[j][k]==i)
  31.                 {
  32.                     count++;
  33.                 }
  34.             }
  35.         }
  36.         cout << count << endl;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement