# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528246 | rainboy | Autobus (COCI22_autobus) | C11 | 137 ms | 1632 KiB |
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 <stdio.h>
#include <string.h>
#define N 70
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int main() {
static int ww[N][N], dd[N][N][N];
int n, m, q, i, j, k, l;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
memset(ww[i], 0x3f, n * sizeof *ww[i]), ww[i][i] = 0;
while (m--) {
int w;
scanf("%d%d%d", &i, &j, &w), i--, j--;
ww[i][j] = min(ww[i][j], w);
}
for (i = 0; i < n; i++)
memset(dd[0][i], 0x3f, n * sizeof *dd[0][i]), dd[0][i][i] = 0;
for (l = 0; l < n; l++) {
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
dd[l + 1][i][j] = INF;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
for (k = 0; k < n; k++)
dd[l + 1][i][k] = min(dd[l + 1][i][k], dd[l][i][j] + ww[j][k]);
}
scanf("%d%d", &l, &q), l = min(l, n - 1);
while (q--) {
scanf("%d%d", &i, &j), i--, j--;
printf("%d\n", dd[l][i][j] == INF ? -1 : dd[l][i][j]);
}
return 0;
}
Compilation message (stderr)
# | 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... |