diff --git a/ConsoleApplication1/.vs/ConsoleApplication1/v14/.suo b/ConsoleApplication1/.vs/ConsoleApplication1/v14/.suo new file mode 100644 index 000000000..d32116f84 Binary files /dev/null and b/ConsoleApplication1/.vs/ConsoleApplication1/v14/.suo differ diff --git a/ConsoleApplication1/ConsoleApplication1.VC.db b/ConsoleApplication1/ConsoleApplication1.VC.db new file mode 100644 index 000000000..022789fe0 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1.VC.db differ diff --git a/ConsoleApplication1/ConsoleApplication1.sln b/ConsoleApplication1/ConsoleApplication1.sln new file mode 100644 index 000000000..ef80f0413 --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.vcxproj", "{F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}.Debug|x64.ActiveCfg = Debug|x64 + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}.Debug|x64.Build.0 = Debug|x64 + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}.Debug|x86.ActiveCfg = Debug|Win32 + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}.Debug|x86.Build.0 = Debug|Win32 + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}.Release|x64.ActiveCfg = Release|x64 + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}.Release|x64.Build.0 = Release|x64 + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}.Release|x86.ActiveCfg = Release|Win32 + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ConsoleApplication1/ConsoleApplication1/Algorithm.h b/ConsoleApplication1/ConsoleApplication1/Algorithm.h new file mode 100644 index 000000000..68d05c98c --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/Algorithm.h @@ -0,0 +1,80 @@ +#ifndef ALGORITHM_H +#define ALGORITHM_H + + + +#include "Priority_Queue.h" +#include "D_Heap.h" +#include "Graph.h" + +using namespace std; + +template +class Algorithm +{ +public: + static KeyType* Dijkstra(int, KeyType *&, Graph*&); +}; + + + +template +KeyType* Algorithm::Dijkstra(int s, KeyType *&P, Graph*& gr) +{ + int n = gr->GetCount(); + int m = gr->GetEdgeSize(); + KeyType **graph = new KeyType*[n]; + for (int i = 0; i < n; i++) + graph[i] = new KeyType[n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + graph[i][j] = -1; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + { + if (gr->GetEdge(j)->from == i) + graph[gr->GetEdge(j)->to][gr->GetEdge(j)->from] = gr->GetEdge(j)->weight; + if (gr->GetEdge(j)->to == i) + graph[gr->GetEdge(j)->from][gr->GetEdge(j)->to] = gr->GetEdge(j)->weight; + + } + + KeyType *distance = new KeyType[n]; + int *vis = new int[n]; + for (int i = 0; i < n; i++) + vis[i] = -1; + vis[0] = s; + int w, min; + for (int i = 0; i < n; i++) + { + if (graph[s][i] == -1) + distance[i] = max_heap; + else distance[i] = graph[s][i]; + } + for (int i = 1; i < n - 1; i++) + { + min = max_heap; + for (int k = 0; k < n; k++) { + if (distance[k] < min && k != s && !gr->Scan(k, vis)) + { + w = k; + min = distance[k]; + } + } + if (min == max_heap) + break; + vis[i] = w; + for (int j = 1; j < n + 1; j++) + { + if (!gr->Scan(j, vis) && graph[w][j] != -1 && (distance[w] + graph[w][j]) <= distance[j]) + { + P[j] = w; + distance[j] = distance[w] + graph[w][j]; + } + } + } + + distance[s] = 0; + return distance; +} +#endif \ No newline at end of file diff --git a/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.vcxproj b/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.vcxproj new file mode 100644 index 000000000..2eedfe1a3 --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {F3555E5A-C1ED-4218-88A5-7E25F93E6DD6} + Win32Proj + ConsoleApplication1 + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + NotUsing + NotUsing + + + + + + + + + + + + \ No newline at end of file diff --git a/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.vcxproj.filters b/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.vcxproj.filters new file mode 100644 index 000000000..5075a329b --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/ConsoleApplication1/ConsoleApplication1/D_Heap.h b/ConsoleApplication1/ConsoleApplication1/D_Heap.h new file mode 100644 index 000000000..c26b5529a --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/D_Heap.h @@ -0,0 +1,224 @@ +#ifndef D_HEAP_H +#define D_HEAP_H +#include +#include + +#define max_heap 10000 + +using namespace std; + +template +class Prior +{ +public: + KeyType pr; +}; + +template +class Distance : public Prior +{ +public: + int vertice; + Distance(int, KeyType); +}; + +template +class D_heap +{ +public: + int d; + Prior** keys; + int count; +public: + D_heap(int, int); + D_heap(const D_heap&); + ~D_heap(); + int GetParent(int); + void Swap(const int, const int); + void SiftUp(int); + void SiftDown(int); + int MinChild(int); + void RemoveMin(); + void Remove(int); + void Push(KeyType); + void Heapify(); + int operator==(const D_heap&) const; + D_heap& operator=(const D_heap&); + int GetCount(); +}; + +template +Distance::Distance(int v, KeyType w) +{ + vertice = v; + pr = w; +} + +template +D_heap::D_heap(const int arity, const int s) +{ + if (arity <= 0) + break; //àðíîñòü ïîëîæèòåëüíàÿ + if ((s < 0) || (s > max_heap)) + break; // íåâåðíûé ðàçìåð + d = arity; + count = s; + keys = new Prior*[max_heap]; +}; + +template +D_heap::D_heap(const D_heap &heap) +{ + d = heap.d; + count = heap.count; + keys = new Prior*[max_heap]; + for (int i = 0; i <= count - 1; i++) + keys[i] = heap.keys[i]; +}; + +template +D_heap::~D_heap() +{ + delete[]keys; +} + +template +int D_heap::GetParent(int x) +{ + int p; + return p = (x - 1) / d; +} + +template +void D_heap::Swap(const int x, const int y) +{ + if ((x > count - 1) || (y > count - 1)) + break; //íåâåðíûé èíäåêñ + Prior *tmp = new Prior; + tmp->pr = keys[x]->pr; + keys[x]->pr = keys[y]->pr; + keys[y]->pr = tmp->pr; +} + +template +void D_heap::SiftUp(int x) +{ + if (x > count - 1) + break; //íåâåðíûé èíäåêñ + int p = GetParent(x); + while ((p >= 0) && (keys[p]->pr > keys[x]->pr)) + { + if (p == 0) + { + Swap(x, p); + return; + } + Swap(x, p); + x = p; + p = GetParent(x); + } +} + +template +int D_heap::MinChild(int x) +{ + if (x * d + 1 > count - 1) + return -1; + int minc = x * d + 1; + int maxc; + if (x * d + d < count - 1) + maxc = x * d + d; + else + maxc = count - 1; + for (int i = minc; i <= maxc; i++) + if (keys[i]->pr < keys[minc]->pr) + minc = i; + return minc; +} + +template +void D_heap::SiftDown(int x) +{ + if (x > count) + break;//íåâåðíûé èíäåêñ + int c = MinChild(x); + while ((c != -1) && (keys[c]->pr < keys[x]->pr)) + { + Swap(c, x); + x = c; + c = MinChild(x); + } +} + +template +void D_heap::RemoveMin() +{ + keys[0] = keys[count - 1]; + count--; + SiftDown(0); +} + +template +void D_heap::Remove(int x) +{ + if (x >= count) + break;//íåâåðíûé èíäåêñ + Swap(x, count - 1); + count--; + if (keys[x]->pr < keys[GetParent(x)]->pr) + SiftUp(x); + else SiftDown(x); +} + +template +void D_heap::Push(KeyType x) +{ + Prior* tmp2 = new Prior; + tmp2->pr = x; + count++; + if (count > max_heap) + break; //äêó÷à çàïîëíåíà + Prior** tmp = new Prior*[max_heap]; + for (int i = 0; i < count - 1; i++) + tmp[i] = keys[i]; + tmp[count - 1] = tmp2; + keys = tmp; +} + +template +void D_heap::Heapify() +{ + if (count == 0) + break; // äêó÷à ïóñòà + for (int i = count - 1; i >= 0; i--) + SiftDown(i); +} + +template +int D_heap::operator==(const D_heap& heap) const +{ + if (heap.count != count) + return 0; + for (int i = 0; i < heap.count; i++) + if (keys[i]->pr != heap.keys[i]->pr) + return 0; + return 1; +} + + +template +D_heap& D_heap::operator=(const D_heap& heap) +{ + d = heap.d; + count = heap.count; + for (int i = 0; i < count; i++) + keys[i] = heap.keys[i]; + return *this; +} + +template +int D_heap::GetCount() +{ + return count; +} +#endif \ No newline at end of file diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.command.1.tlog b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.command.1.tlog new file mode 100644 index 000000000..a6afdf525 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.command.1.tlog differ diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.read.1.tlog b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.read.1.tlog new file mode 100644 index 000000000..cf8614555 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.read.1.tlog differ diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.write.1.tlog b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.write.1.tlog new file mode 100644 index 000000000..b4c719e22 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/CL.write.1.tlog differ diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/ConsoleApplication1.lastbuildstate b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/ConsoleApplication1.lastbuildstate new file mode 100644 index 000000000..1ab2282a0 --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/ConsoleApplication1.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1 +Debug|Win32|C:\Users\Леонид\Desktop\лаб\dejkstra\ConsoleApplication1\| diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.command.1.tlog b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.command.1.tlog new file mode 100644 index 000000000..9e6f1a003 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.command.1.tlog differ diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.read.1.tlog b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.read.1.tlog new file mode 100644 index 000000000..b7564b709 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.read.1.tlog differ diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.write.1.tlog b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.write.1.tlog new file mode 100644 index 000000000..aafddb2f0 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleA.F3555E5A.tlog/link.write.1.tlog differ diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleApplication1.log b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleApplication1.log new file mode 100644 index 000000000..136715ade --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/Debug/ConsoleApplication1.log @@ -0,0 +1,17 @@ + main.cpp +c:\users\леонид\desktop\лаб\dejkstra\consoleapplication1\consoleapplication1\main.cpp(41): warning C4244: '=': conversion from 'int' to 'KeyType', possible loss of data +c:\users\леонид\desktop\лаб\dejkstra\consoleapplication1\consoleapplication1\algorithm.h(61): warning C4244: '=': conversion from 'KeyType' to 'int', possible loss of data + c:\users\леонид\desktop\лаб\dejkstra\consoleapplication1\consoleapplication1\algorithm.h(23): note: while compiling class template member function 'KeyType *Algorithm::Dijkstra(int,KeyType *&,Graph *&)' + with + [ + KeyType=KeyType + ] + c:\users\леонид\desktop\лаб\dejkstra\consoleapplication1\consoleapplication1\main.cpp(42): note: see reference to function template instantiation 'KeyType *Algorithm::Dijkstra(int,KeyType *&,Graph *&)' being compiled + with + [ + KeyType=KeyType + ] + c:\users\леонид\desktop\лаб\dejkstra\consoleapplication1\consoleapplication1\main.cpp(42): note: see reference to class template instantiation 'Algorithm' being compiled +c:\users\леонид\desktop\лаб\dejkstra\consoleapplication1\consoleapplication1\algorithm.h(71): warning C4244: '=': conversion from 'int' to 'KeyType', possible loss of data + ConsoleApplication1.vcxproj -> C:\Users\Леонид\Desktop\лаб\dejkstra\ConsoleApplication1\Debug\ConsoleApplication1.exe + ConsoleApplication1.vcxproj -> C:\Users\Леонид\Desktop\лаб\dejkstra\ConsoleApplication1\Debug\ConsoleApplication1.pdb (Full PDB) diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/vc140.idb b/ConsoleApplication1/ConsoleApplication1/Debug/vc140.idb new file mode 100644 index 000000000..93d0b1d85 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1/Debug/vc140.idb differ diff --git a/ConsoleApplication1/ConsoleApplication1/Debug/vc140.pdb b/ConsoleApplication1/ConsoleApplication1/Debug/vc140.pdb new file mode 100644 index 000000000..11be2b085 Binary files /dev/null and b/ConsoleApplication1/ConsoleApplication1/Debug/vc140.pdb differ diff --git a/ConsoleApplication1/ConsoleApplication1/Graph.h b/ConsoleApplication1/ConsoleApplication1/Graph.h new file mode 100644 index 000000000..c7159e2d1 --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/Graph.h @@ -0,0 +1,146 @@ +#ifndef GRAPH_H +#define GRAPH_H + +#include +#include +#include +#include +using namespace std; + + +template +class Edge +{ +public: + Edge(int, int, KeyType); + int from; + int to; + KeyType weight; +}; + +template +class Graph +{ +private: + int n; //âåðøèíû + int m; //ðåáðà + Edge** edges; + int current; //òåêóùåå ðåáðî +public: + Graph(int, int); + ~Graph(); + void Push(int, int, KeyType); + void Remove(int, int); + int GetCount(); + int GetEdgeSize(); + Edge* GetEdge(int); + KeyType GetWeight(int, int); + void Print(); + bool Scan(int, int*); +}; + +template +Edge::Edge(int f, int t, KeyType w) +{ + from = f; + to = t; + weight = w; +} + +template +Graph::Graph(int v, int e) +{ + if (v < 0) + return; //íåêîððåêòíàÿ âåðøèíà + else + n = v; + if ((e < 0) || (e > n * (n - 1) / 2)) + return; //íåêîððåêòíîå ðåáðî + else + m = e; + current = 0; + edges = new Edge*[m]; +} + +template +Graph::~Graph() +{ + for (int i = 0; i < current; i++) + delete edges[i]; + delete[] edges; +} + +template +void Graph::Push(int f, int t, KeyType w) +{ + if (current == m) + return; // ãðàô ïîëîí + if (f == t) + return; //ãðàô íå äîëæåí ñîäåðæàòü ïåòëåé + if ((f > n) || (t > n)) + return;//òàêèõ âåðøèí íå ñóùåñòâóåò + edges[current] = new Edge(f, t, w); + current++; +} + +template +int Graph::GetCount() +{ + return n; +} + +template +int Graph::GetEdgeSize() +{ + return m; +} + +template +KeyType Graph::GetWeight(int f, int t) +{ + if ((f < 0) || (f > n) || (t < 0) || (t > n)) + return;// íåêîððåêòíûå âåðøèíû + for (int i = 0; i < current; i++) + if ((edges[i]->from == f) && (edges[i]->to == t) || (edges[i]->from == t) && (edges[i]->to == f)) + return edges[i]->weight; + return 0; +} + +template +void Graph::Print() +{ + cout << "Îò äî " << endl; + for (int i = 0; i < n; i++) + for (int j = 0; j < current; j++) + if (edges[j]->from == i) + cout << edges[j]->from + 1 << " " << edges[j]->to + 1 << "(" << edges[j]->weight << ")" << endl; +} + +template +Edge* Graph::GetEdge(int x) +{ + return edges[x]; +} + +template +void Graph::Remove(int f, int t) +{ + int tmp = FindEdge(f, t); + if (tmp == -1) + return; // òàêîãî ðåáðà íåò + delete edges[tmp]; + edges[tmp] = edges[current - 1]; + current--; +} + +template +bool Graph::Scan(int f, int* b) +{ + bool res = false; + for (int i = 0; i < n; i++) + if (b[i] == f) + res = true; + return res; +} + +#endif \ No newline at end of file diff --git a/ConsoleApplication1/ConsoleApplication1/Priority_Queue.h b/ConsoleApplication1/ConsoleApplication1/Priority_Queue.h new file mode 100644 index 000000000..6fea696e1 --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/Priority_Queue.h @@ -0,0 +1,70 @@ +#ifndef PRIORITY_QUEUE_H +#define PRIORITY_QUEUE_H +#include "D_Heap.h" + +template +class Priority_queue +{ +public: + Priority_queue(void) {}; + virtual ~Priority_queue() {}; + virtual void Push(const KeyType) = 0; + virtual void Pop() = 0; + virtual int IsEmpty() = 0; + virtual int GetSize() = 0; + virtual KeyType Top() = 0; +}; + +template +class Queue_on_heap : public Priority_queue +{ +private: + D_heap *heap; +public: + Queue_on_heap(int); + virtual ~Queue_on_heap() { delete heap; } + void Push(const KeyType); + void Pop(); + KeyType Top(); + int IsEmpty(); + virtual int GetSize() { return heap->GetCount(); }; +}; + +template +Queue_on_heap::Queue_on_heap(int arity) +{ + if (arity < 0) + break; + heap = new D_heap(arity, 0); +} + +template +void Queue_on_heap::Pop() +{ + if (IsEmpty()) + break; + heap->RemoveMin(); +} + +template +int Queue_on_heap::IsEmpty() +{ + return heap->GetCount() == 0; +}; + +template +void Queue_on_heap::Push(const KeyType x) +{ + heap->Push(x); + heap->Sort(); +} + +template +KeyType Queue_on_heap::Top() +{ + if (IsEmpty()) + break; + return heap->GetKey(0)->pr; +} + +#endif \ No newline at end of file diff --git a/ConsoleApplication1/ConsoleApplication1/main.cpp b/ConsoleApplication1/ConsoleApplication1/main.cpp new file mode 100644 index 000000000..cfbe883a5 --- /dev/null +++ b/ConsoleApplication1/ConsoleApplication1/main.cpp @@ -0,0 +1,58 @@ +#include +#include "Graph.h" +#include "Priority_Queue.h" +#include "Algorithm.h" + + +typedef float KeyType; + +using namespace std; + +int main() +{ + setlocale(LC_CTYPE, "Russian"); + cout << "Ââåäèòå êîëè÷åñòâî âåðøèí:" << endl; + int n; + cin >> n; + cout << "Ââåäèòå êîëè÷åñòâî ð¸áåð" << endl; + int m; + cin >> m; + Graph *graph = new Graph(n, m); + KeyType *P = new KeyType[n]; + + for (int i = 0; i> f; + cin >> t; + cin >> w; + graph->Push(f - 1, t - 1, w); + } + + system("cls"); + cout << "Ãðàô: " << endl << endl; + graph->Print(); + cout << "Çàäàéòå íà÷àëüíóþ âåðøèíó:" << endl; + int a; + cin >> a; + for (int i = 0; i <= n; i++) + P[i] = a - 1; + KeyType *dist = Algorithm::Dijkstra(a - 1, P, graph); + cout << "Èòîã: " << endl << endl; + for (int i = 1; i