summaryrefslogtreecommitdiff
path: root/graphs-algo/task1.cpp
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2021-04-04 19:51:59 +0400
committerAndrew Guschin <saintruler@gmail.com>2021-04-04 19:51:59 +0400
commit31b49d6551e068f41daae6e38d88bfe8bf5bfb23 (patch)
tree223f210fe6560a6b8578190a66ccf78ab481c89e /graphs-algo/task1.cpp
parent2ff0384a6e5e697f97d640c7195dcd52c310b42b (diff)
Починил алгоритм Дейкстры
Diffstat (limited to 'graphs-algo/task1.cpp')
-rw-r--r--graphs-algo/task1.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/graphs-algo/task1.cpp b/graphs-algo/task1.cpp
index cd96c72..d6d2a83 100644
--- a/graphs-algo/task1.cpp
+++ b/graphs-algo/task1.cpp
@@ -2,6 +2,7 @@
#include<vector>
#include<algorithm>
#include<iomanip>
+#include<stdio.h>
using namespace std;
@@ -74,6 +75,7 @@ graph dijkstra(graph g, int n)
v = p;
}
}
+ if (v == -1) continue;
u[s][v] = 1;
// Производим релаксации
@@ -103,6 +105,11 @@ vector<int> backtrack(graph paths, int start, int end)
{
path.push_back(cur);
cur = paths[start][cur];
+ if (cur == -1)
+ {
+ path.clear();
+ return path;
+ }
}
path.push_back(start);
reverse(path.begin(), path.end());