This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "race.h"
#define inf 1<<20
int best_path(int N, int K, int H[][2], int L[])
{
int dis[N][N][2];
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
dis[i][j][0] = dis[i][j][1] = (i==j)?0:inf;
}
for(int i=0; i<N; i++) {
dis[H[i][0]][H[i][1]][0] = dis[H[i][1]][H[i][0]][0] = L[i];
dis[H[i][0]][H[i][1]][1] = dis[H[i][1]][H[i][0]][1] = 1;
}
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
for(int k=0; k<N; k++) {
if(dis[i][k][0] > dis[i][j][0]+dis[j][k][0]) {
dis[i][k][0] = dis[k][i][0] = dis[i][j][0]+dis[j][k][0];
dis[i][k][1] = dis[k][i][1] = dis[i][j][1]+dis[j][k][1];
}
}
int opt = -1;
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
if(dis[i][j][0] == K and (dis[i][j][1] < opt or opt==-1) ) opt = dis[i][j][1];
}
return opt;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |