forked from Biswajitghosh98/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
w.cpp
41 lines (38 loc) · 961 Bytes
/
w.cpp
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
39
40
41
#include <bits/stdc++.h>
using namespace std;
void addEdge(vector <pair<int, int> > adj[], int u,
int v, int wt)
{
adj[u].push_back(make_pair(v, wt));
}
void printGraph(vector<pair<int,int> > adj[], int V)
{
int v, w;
vector <pair<int, int> >::iterator it;
for (int u = 0; u < V; u++)
{
cout << "Node " << u << " makes an edge with \n";
for (it = adj[u].begin(); it!=adj[u].end(); it++)
{
v = it->first;
w = it->second;
cout << "\tNode " << v << " with edge weight ="
<< w << "\n";
}
cout << "\n";
}
}
int main()
{
int V = 5;
vector<pair<int, int> > adj[V];
addEdge(adj, 0, 1, 10);
addEdge(adj, 0, 4, 20);
addEdge(adj, 1, 2, 30);
addEdge(adj, 1, 3, 40);
addEdge(adj, 1, 4, 50);
addEdge(adj, 2, 3, 60);
addEdge(adj, 3, 4, 70);
printGraph(adj, V);
return 0;
}