summaryrefslogtreecommitdiff
path: root/content/graph/bellmannFord.cpp
blob: cadcde7c734d613909df50ab3f19c8941622b642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
auto bellmannFord(int n, vector<edge>& edges, int start) {
	vector<ll> dist(n, INF), prev(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;
				prev[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; //return prev?
}