Created
March 5, 2018 14:40
-
-
Save MuhammadJahidHasan/7212b308abbddb7afca7115b6a3208fa to your computer and use it in GitHub Desktop.
How to represent graph list in c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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