-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
38 lines (35 loc) · 713 Bytes
/
graph.cpp
File metadata and controls
38 lines (35 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// #include<iostream>
// using namespace std;
#include<bits/stdc++.h>
using namespace std;
void addEdge(vector<int> G[],int u,int v)
{
G[u].push_back(v);
G[v].push_back(u);
}
void printGraph(vector<int> adj[], int V)
{
for(int v=0;v<V;++v)
{
cout<<"\nAdjacency of vertex "<<v<<" head\n";
for(auto x:adj[v])
cout<<x<<" ";
}
}
int main() {
int n,e,u,v;
cout<<"\nEnter No. of vertices:\n";
cin>>n;
cout<<"\nEnter no. of edges:\n";
cin>>e;
vector<int> G[n];
for(int i=0;i<e;i++)
{
cout<<"\nEnter start and end:\n";
cin>>u>>v;
addEdge(G,u,v);
}
cout<<"\nGraph Built!!\n";
printGraph(G,n);
return 0;
}