帮忙排版一下代码#include <stdio.h>
#define N 20
#define INF -1
void floydWarshall(int graph[N][N], int n) {
int i, j, k;
for (k = 0; k < n; k++) {
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (graph[i][k] != INF && graph[k][j] != INF &&
(graph[i][j] == INF || graph[i][k] + graph[k][j] < graph[i][j])) {
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
}
void printEccentricities(int graph[N][N], int n) {
int i,j;
int eccentricity, maxEccentricity;
for ( i = 0; i < n; i++) {
maxEccentricity = 0;
for ( j = 0; j < n; j++) {
if (graph[i][j] > maxEccentricity) {
maxEccentricity = graph[i][j];
}
}
printf("%d ", maxEccentricity);
}
}
int main() {
int n, graph[N][N];
int i,j;
// 读取村庄数和邻接矩阵
scanf("%d", &n);
for ( i = 0; i < n; i++) {
for ( j = 0; j < n; j++) {
scanf("%d", &graph[i][j]);
}
}
// 使用 Floyd-Warshall 算法计算最短路径
floydWarshall(graph, n);
// 输出村庄的偏心度
//printEccentricities(graph, n);
return 0;
}
|