Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int v;
- int e;
- cout<<"Enter vertex and edges \n";
- cin>>v;
- cin>>e;
- vector<vector<int> >graph(v);
- for(int i=0; i<e; i++){
- int a,b;
- cout<<"Enter Two nodes which are connected \n";
- cin>>a;
- cin>>b;
- graph[a].push_back(b);
- graph[b].push_back(a);//Remove this if you want directed
- }
- for(int i = 0; i<v; i++){
- for(int j = 0; j<graph[i].size(); j++){
- cout<<graph[i][j]<<" ";
- }
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement