Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, e;
- cout << "How many nodes?: " << endl;
- cin >> n;
- int a[n][n];
- memset(a, 0, (sizeof(a)*2));
- for(int i=1; i<=n; i++)
- {
- cout << "How many edges is node "<< i << " connecting to?: " << endl;
- cin >> e;
- cout << "Enter " << e << " nodes" << endl;
- for(int j=1; j<=e; j++)
- {
- int x;
- cin >> x;
- a[i][x] = 1;
- }
- }
- for(int i=1; i<=n; i++)
- {
- for(int j=1; j<=n; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- for(int i=1;i<=n;i++)
- {
- int out = 0;
- for(int j=1;j<=n;j++)
- {
- if(a[i][j]==1)
- out++;
- }
- cout << "Outdegree of " << i << " is " << out;
- cout << endl;
- }
- cout << endl;
- for(int i=1;i<=n;i++)
- {
- int in = 0;
- for(int j=1;j<=n;j++)
- {
- if(a[j][i]==1)
- in++;
- }
- cout << "Indegree of " << i << " is " << in;
- cout << endl;
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement