-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
adjacency_list.cpp
49 lines (38 loc) · 1.62 KB
/
adjacency_list.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
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
#define pb push_back
int main() {
vector<vii> AdjList;
vii vectorOfPairs;
vectorOfPairs.pb(make_pair(1, 50)); // Vertice 0 connected with vertice 1 and weight 50
AdjList.pb(vectorOfPairs);
vectorOfPairs.clear();
vectorOfPairs.pb(make_pair(0, 50)); // Vertice 0 connected with vertice 1 and weight 50
vectorOfPairs.pb(make_pair(2, 20)); // Vertice 1 connected with vertice 2 and weight 20
vectorOfPairs.pb(make_pair(3, 30)); // Vertice 1 connected with vertice 3 and weight 30
AdjList.pb(vectorOfPairs);
vectorOfPairs.clear();
vectorOfPairs.pb(make_pair(1, 20)); // Vertice 2 connected with vertice 1 and weight 20
vectorOfPairs.pb(make_pair(3, 40)); // Vertice 2 connected with vertice 3 and weight 40
AdjList.pb(vectorOfPairs);
vectorOfPairs.clear();
vectorOfPairs.pb(make_pair(1, 30)); // Vertice 3 connected with vertice 1 and weight 30
vectorOfPairs.pb(make_pair(2, 40)); // Vertice 2 connected with vertice 3 and weight 40
vectorOfPairs.pb(make_pair(4, 60)); // Vertice 3 connected with vertice 4 and weight 60
AdjList.pb(vectorOfPairs);
vectorOfPairs.clear();
vectorOfPairs.pb(make_pair(3, 60)); // Vertice 4 connected with vertice 3 and weight 60
AdjList.pb(vectorOfPairs);
for (int i = 0; i < AdjList.size(); i++) {
for (int j = 0; j < AdjList[i].size(); j++) {
cout << "Vertice: " << i;
cout << " connected with vertice " << AdjList[i][j].first;
cout << " with weight " << AdjList[i][j].second << endl;
}
cout << endl;
}
return 0;
}