#include #include int min(int **pathcost, int i, int j, int k) { int min; if (pathcost[i][j] == -1) { if ((pathcost[i][k] == -1) || (pathcost[k][j] == -1)) { min = -1; } else { min = pathcost[i][k] + pathcost[k][j]; } } else { if ((pathcost[i][k] == -1) || (pathcost[k][j] == -1)) { min = pathcost[i][j]; } else { if (pathcost[i][j] < (pathcost[i][k] + pathcost[k][j])) { min = pathcost[i][j]; } else { min = pathcost[i][k] + pathcost[k][j]; } } } return min; } int total(int **pathcost, int *S, int i, int j, int N) { int total; if ((pathcost[0][i] == -1)|| (pathcost[i][j] == -1)|| (pathcost[j][N-1] == -1)) { total = -1; } else { total = pathcost[0][i] + S[i] + pathcost[i][j] + S[j] + pathcost[j][N-1]; } return total; } int main() { int N; int *S; int M; int *A; int *B; int *C; scanf("%d", &N); S = (int*)malloc(sizeof(int)*N); int i; for (i=0; i