Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MuhammadJahidHasan/7212b308abbddb7afca7115b6a3208fa to your computer and use it in GitHub Desktop.
Save MuhammadJahidHasan/7212b308abbddb7afca7115b6a3208fa to your computer and use it in GitHub Desktop.
How to represent graph list in c++
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define MAX 10000
vector <int> edges[MAX];
vector<int>cost[MAX];
set<int> s;
int main()
{
int N,E,i;
cin>>N>>E;
for(int i=0;i<E;i++){
int x,y;
cin>>x>>y;
s.insert(x);
edges[x].push_back(y);
}
set< int > :: iterator it;
for(it = s.begin(); it != s.end(); it++){
cout<<*it<<"==";
for(int j=0;j<edges[*it].size();j++){
cout<<edges[*it][j]<<" ";
}
cout<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment