///Derectional graph
///Adjacency Matrix
#include<bits/stdc++.h>
#define N 100020
using namespace std;
int indegree[N], outdegree[N];
int main()
{
int node, edge, i, j, first_node, second_node;
cout << "Enter Node Number :: ";
cin >> node;
cout << "Enter Edge Number :: ";
cin >> edge;
cout << "\nEnter Edges :: \n";
for(i=1; i<=edge; i++)
{
cin >> first_node >> second_node;
outdegree[first_node]++;
indegree[second_node]++;
}
cout << "\nDegree Of Node Are :: \n";
for(i=1; i<=node; i++)
{
cout << "Node :: " << i << "\n";
cout << "Indegree :: " << indegree[i] << "\n";
cout << "Outdegree :: " << outdegree[i] << "\n\n";
}
return 0;
}
///Adjacency Matrix
#include<bits/stdc++.h>
#define N 100020
using namespace std;
int indegree[N], outdegree[N];
int main()
{
int node, edge, i, j, first_node, second_node;
cout << "Enter Node Number :: ";
cin >> node;
cout << "Enter Edge Number :: ";
cin >> edge;
cout << "\nEnter Edges :: \n";
for(i=1; i<=edge; i++)
{
cin >> first_node >> second_node;
outdegree[first_node]++;
indegree[second_node]++;
}
cout << "\nDegree Of Node Are :: \n";
for(i=1; i<=node; i++)
{
cout << "Node :: " << i << "\n";
cout << "Indegree :: " << indegree[i] << "\n";
cout << "Outdegree :: " << outdegree[i] << "\n\n";
}
return 0;
}
Comments
Post a Comment