From 65b7c7072d7003013f36998982cbf73af4612d84 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 1 Jan 2024 11:05:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E4=BA=86=E8=BF=AA=E6=9D=B0=E6=96=AF?= =?UTF-8?q?=E7=89=B9=E6=8B=89=E7=AE=97=E6=B3=95=E7=9A=84=E4=B8=80=E4=B8=AA?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 1b177fd..147092f 100644 --- a/main.cpp +++ b/main.cpp @@ -273,10 +273,14 @@ void Dijkstra(Graph* g, int src) { } } + for (int i = 0; i < V; i++) + if (dist[i] == INT_MAX) + dist[i] = -1; + // 打印构造的最短路径 - printf("Vertex Distance from Source\n"); + printf("顶点\t距离\n"); for (int i = 0; i < V; i++) - printf("%d \t\t %d\n", i, dist[i]); + printf("%d\t%d\n", i, dist[i]); // 释放动态分配的内存 free(dist); @@ -427,19 +431,19 @@ int main() { switch (choice) { case 1: - printf("输入开始搜索的顶点索引:"); + printf("输入开始搜索的顶点:"); scanf("%d", &startVertex); DFS(graph, startVertex); printf("\n\n"); break; case 2: - printf("输入开始搜索的顶点索引:"); + printf("输入开始搜索的顶点:"); scanf("%d", &startVertex); BFS(graph, startVertex); printf("\n\n"); break; case 3: - printf("输入开始顶点的索引:"); + printf("输入开始顶点:"); scanf("%d", &startVertex); Prim(graph, startVertex); break; @@ -448,6 +452,8 @@ int main() { printf("\n\n"); break; case 5: + printf("输入开始顶点:"); + scanf("%d", &startVertex); Dijkstra(graph, startVertex); printf("\n\n"); break;