-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.h
More file actions
30 lines (25 loc) · 678 Bytes
/
Copy pathgraph.h
File metadata and controls
30 lines (25 loc) · 678 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
#ifndef GRAPH_H
#define GRAPH_H
#include <vector>
#include <utility>
#include <stdexcept>
using namespace std; // make standard library names shorter
// structure for an edge (u,v) with weight w
struct Edge
{
int u, v;
int w;
Edge(int a = 0, int b = 0, int c = 0) : u(a), v(b), w(c) {}
};
// graph class for adjacency list + edge list
class Graph
{
public:
int n;
vector<vector<pair<int, int>>> adj;
vector<Edge> edges;
Graph(int nodes = 0);
void add_edge(int a, int b, int w); // add undirected edge
static Graph from_cost_matrix(const vector<vector<int>> &mat); // build from cost matrix
};
#endif // GRAPH_H