From 31b49d6551e068f41daae6e38d88bfe8bf5bfb23 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Sun, 4 Apr 2021 19:51:59 +0400 Subject: =?UTF-8?q?=D0=9F=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D0=BB=20=D0=B0?= =?UTF-8?q?=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC=20=D0=94=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D1=81=D1=82=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphs-algo/Makefile | 2 ++ graphs-algo/task1.cpp | 7 +++++++ 2 files changed, 9 insertions(+) (limited to 'graphs-algo') diff --git a/graphs-algo/Makefile b/graphs-algo/Makefile index 7cdaf2a..5343597 100644 --- a/graphs-algo/Makefile +++ b/graphs-algo/Makefile @@ -9,6 +9,8 @@ test1: task1 @printf "Answer: \n" @printf "4\n4\n1 2 1\n2 3 5\n3 4 1\n4 1 2\n2\n3" | ./task.out @printf "Answer: \n" + @printf "3\n1\n1 2 1\n1 2" | ./task.out + @printf "Answer: \n" task2: $(COMPILE) -o task.out task2.cpp 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 #include #include +#include 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 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()); -- cgit v1.2.3