summaryrefslogtreecommitdiff
path: root/graph/bellmannFord.cpp
blob: 7ba51c0b7f35f24955ead9be8a2cb043ed2d615d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void bellmannFord(int n, vector<edge> edges, int start) {
	vector<ll> dist(n, INF), parent(n, -1);
	dist[start] = 0;

	for (int i = 1; i < n; i++) {
		for (edge& e : edges) {
			if (dist[e.from] != INF &&
			    dist[e.from] + e.cost < dist[e.to]) {
				dist[e.to] = dist[e.from] + e.cost;
				parent[e.to] = e.from;
	}}}

	for (edge& e : edges) {
		if (dist[e.from] != INF &&
		    dist[e.from] + e.cost < dist[e.to]) {
			// Negativer Kreis gefunden.
	}}
	//return dist, parent;
}