///Directional Graph
///Adjacency List
#include<bits/stdc++.h>
#define N 10020
using namespace std;
vector<int>indegree[N], outdegree[N];
int main()
{
int node, edge, i, j, u, v;
cout << "Enter Node Number :: ";
cin >> node;
cout << "Enter Edge Number :: ";
cin >> edge;
cout << "\nEnter Edges :: \n";
for(i=1;i<=edge;i++)
{
cin >> u >> v;
indegree[v].push_back(u);
outdegree[u].push_back(v);
}
cout << "\nDegree Of Node Are :: \n";
for(i=1;i<=node;i++)
{
cout << "Node " << i << "\n";
cout << "Indegree :: " << indegree[i].size() << "\n";
cout << "Outdegree :: " << outdegree[i].size() << "\n\n";
}
return 0;
}
///Adjacency List
#include<bits/stdc++.h>
#define N 10020
using namespace std;
vector<int>indegree[N], outdegree[N];
int main()
{
int node, edge, i, j, u, v;
cout << "Enter Node Number :: ";
cin >> node;
cout << "Enter Edge Number :: ";
cin >> edge;
cout << "\nEnter Edges :: \n";
for(i=1;i<=edge;i++)
{
cin >> u >> v;
indegree[v].push_back(u);
outdegree[u].push_back(v);
}
cout << "\nDegree Of Node Are :: \n";
for(i=1;i<=node;i++)
{
cout << "Node " << i << "\n";
cout << "Indegree :: " << indegree[i].size() << "\n";
cout << "Outdegree :: " << outdegree[i].size() << "\n\n";
}
return 0;
}
Comments
Post a Comment