summaryrefslogtreecommitdiff
path: root/graph/bellmannFord.cpp
blob: 21c7dbe01eab212a71d52e6a76f95c16e67c77c8 (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;
}