Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const long long INF = 1e18;
- struct Edge {
- int x, y;
- int cst;
- };
- inline long long BellmanFord(int n, int m, vector <Edge> &edges, int src, int dst) {
- vector <long long> dist(n + 1, INF);
- dist[src] = 0;
- bool ok = 1;
- int step = 0;
- while(ok) {
- ok = 0;
- for(auto &it : edges) {
- if(dist[it.x] + it.cst < dist[it.y]) {
- dist[it.y] = dist[it.x] + it.cst;
- ok = 1;
- }
- }
- if(step > n) {
- cout << "Ciclu negativ";
- exit(0);
- }
- step++;
- }
- return dist[dst];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement