Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define endl "\n"
- #define ll long long
- #define PI acos(-1.0)
- #define test cout<<"\n****\n"
- #define LCM(a,b) ((a/__gcd(a,b))*b)
- #define precise fixed(cout);cout<<setprecision(12)
- #define fast ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define MAX 1000
- vector<int> graph[MAX];
- int in[MAX],out[MAX];
- int main() {
- int NumNodes,NumEdges;
- cout<<"Enter the number of nodes: "<<endl;
- cin>>NumNodes;
- cout<<"Enter the number of edges: "<<endl;
- cin>>NumEdges;
- cout<<"Now Enter Graph Connections: "<<endl;
- for(int i=1;i<=NumEdges;i++){
- int node,edge;
- cin>>node>>edge;
- graph[node].push_back(edge);
- }
- cout<<"Nodes are joined among: "<<endl;
- for(int i=1;i<=NumNodes;i++){
- cout<<i<<">>";
- if(graph[i].size()==0){
- cout<<" NULL\n";
- } else {
- for (int j = 0; j < graph[i].size(); j++) {
- out[i]++;
- in[graph[i][j]]++;
- cout << " " << graph[i][j];
- }
- cout << endl;
- }
- }
- cout<<"Indegree and Outdegree:"<<endl;
- for(int i=1;i<=NumNodes;i++){
- cout<<i<<"-> In:"<<in[i]<<" Out:"<<out[i]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement