diff --git a/TangDou/Topic/HDU1385.cpp b/TangDou/Topic/HDU1385.cpp index 99aa448..79ae0e9 100644 --- a/TangDou/Topic/HDU1385.cpp +++ b/TangDou/Topic/HDU1385.cpp @@ -3,18 +3,18 @@ using namespace std; const int INF = 0x3f3f3f3f; const int N = 1003; -int mp[N][N], path[N][N]; // 邻接矩阵、路径 -int n, x, y, u, v, cost[N]; // 额外费用 +int g[N][N], path[N][N]; // 邻接矩阵、路径 +int n, x, y, cost[N]; // 额外费用 void floyd() { for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) - if (mp[i][k] != INF) + if (g[i][k] != INF) for (int j = 1; j <= n; j++) { - if (mp[i][j] > mp[i][k] + mp[k][j] + cost[k]) { - mp[i][j] = mp[i][k] + mp[k][j] + cost[k]; + if (g[i][j] > g[i][k] + g[k][j] + cost[k]) { + g[i][j] = g[i][k] + g[k][j] + cost[k]; path[i][j] = path[i][k]; } - if (mp[i][j] == mp[i][k] + mp[k][j] + cost[k]) { + if (g[i][j] == g[i][k] + g[k][j] + cost[k]) { if (path[i][j] > path[i][k]) // 字典序 path[i][j] = path[i][k]; } @@ -25,8 +25,8 @@ int main() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { path[i][j] = j; - cin >> mp[i][j]; - if (mp[i][j] == -1) mp[i][j] = INF; + cin >> g[i][j]; + if (g[i][j] == -1) g[i][j] = INF; } } for (int i = 1; i <= n; i++) cin >> cost[i]; @@ -34,22 +34,21 @@ int main() { while (cin >> x >> y) { if (x == -1 && y == -1) break; - u = x, v = y; printf("From %d to %d :\n", x, y); printf("Path: %d", x); - + int u = x, v = y; while (x != y) { printf("-->%d", path[x][y]); x = path[x][y]; } - printf("\n"); + puts(""); - if (mp[u][v] < INF) - printf("Total cost : %d\n", mp[u][v]); + if (g[u][v] < INF) + printf("Total cost : %d\n", g[u][v]); else - printf("-1\n"); - printf("\n"); + puts("-1"); + puts(""); } } return 0;