///Bidirectional Graph
///Adjacency Matrix
#include<bits/stdc++.h>
#define N 100020
using namespace std;
int direction[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;
direction[u]++;
direction[v]++;
}
cout << "\nDegree of Node Are :: \n";
for(i=1;i<=node;i++)
{
cout << "Node " << i << "\n";
cout << "Indegree :: " << direction[i] << "\n";
cout << "Outdegree :: " << direction[i] << "\n\n";
}
return 0;
}
///Adjacency Matrix
#include<bits/stdc++.h>
#define N 100020
using namespace std;
int direction[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;
direction[u]++;
direction[v]++;
}
cout << "\nDegree of Node Are :: \n";
for(i=1;i<=node;i++)
{
cout << "Node " << i << "\n";
cout << "Indegree :: " << direction[i] << "\n";
cout << "Outdegree :: " << direction[i] << "\n\n";
}
return 0;
}
Comments
Post a Comment