Submission #528246

# Submission time Handle Problem Language Result Execution time Memory
528246 2022-02-19T18:14:56 Z rainboy Autobus (COCI22_autobus) C
70 / 70
137 ms 1632 KB
#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

Main.c: In function 'main':
Main.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:19:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%d%d%d", &i, &j, &w), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:33:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d%d", &l, &q), l = min(l, n - 1);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:35:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1612 KB Output is correct
2 Correct 25 ms 1600 KB Output is correct
3 Correct 25 ms 1576 KB Output is correct
4 Correct 25 ms 1624 KB Output is correct
5 Correct 26 ms 1604 KB Output is correct
6 Correct 26 ms 1628 KB Output is correct
7 Correct 27 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 25 ms 1616 KB Output is correct
8 Correct 25 ms 1632 KB Output is correct
9 Correct 25 ms 1604 KB Output is correct
10 Correct 26 ms 1532 KB Output is correct
11 Correct 26 ms 1524 KB Output is correct
12 Correct 25 ms 1632 KB Output is correct
13 Correct 123 ms 1572 KB Output is correct
14 Correct 127 ms 1572 KB Output is correct
15 Correct 130 ms 1560 KB Output is correct
16 Correct 122 ms 1556 KB Output is correct
17 Correct 133 ms 1560 KB Output is correct
18 Correct 130 ms 1556 KB Output is correct
19 Correct 137 ms 1560 KB Output is correct
20 Correct 129 ms 1604 KB Output is correct
21 Correct 126 ms 1560 KB Output is correct
22 Correct 125 ms 1556 KB Output is correct
23 Correct 135 ms 1560 KB Output is correct
24 Correct 124 ms 1564 KB Output is correct
25 Correct 126 ms 1564 KB Output is correct
26 Correct 128 ms 1560 KB Output is correct
27 Correct 129 ms 1628 KB Output is correct
28 Correct 130 ms 1560 KB Output is correct
29 Correct 127 ms 1604 KB Output is correct
30 Correct 123 ms 1576 KB Output is correct
31 Correct 123 ms 1556 KB Output is correct
32 Correct 136 ms 1556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 25 ms 1612 KB Output is correct
8 Correct 25 ms 1600 KB Output is correct
9 Correct 25 ms 1576 KB Output is correct
10 Correct 25 ms 1624 KB Output is correct
11 Correct 26 ms 1604 KB Output is correct
12 Correct 26 ms 1628 KB Output is correct
13 Correct 27 ms 1616 KB Output is correct
14 Correct 25 ms 1616 KB Output is correct
15 Correct 25 ms 1632 KB Output is correct
16 Correct 25 ms 1604 KB Output is correct
17 Correct 26 ms 1532 KB Output is correct
18 Correct 26 ms 1524 KB Output is correct
19 Correct 25 ms 1632 KB Output is correct
20 Correct 123 ms 1572 KB Output is correct
21 Correct 127 ms 1572 KB Output is correct
22 Correct 130 ms 1560 KB Output is correct
23 Correct 122 ms 1556 KB Output is correct
24 Correct 133 ms 1560 KB Output is correct
25 Correct 130 ms 1556 KB Output is correct
26 Correct 137 ms 1560 KB Output is correct
27 Correct 129 ms 1604 KB Output is correct
28 Correct 126 ms 1560 KB Output is correct
29 Correct 125 ms 1556 KB Output is correct
30 Correct 135 ms 1560 KB Output is correct
31 Correct 124 ms 1564 KB Output is correct
32 Correct 126 ms 1564 KB Output is correct
33 Correct 128 ms 1560 KB Output is correct
34 Correct 129 ms 1628 KB Output is correct
35 Correct 130 ms 1560 KB Output is correct
36 Correct 127 ms 1604 KB Output is correct
37 Correct 123 ms 1576 KB Output is correct
38 Correct 123 ms 1556 KB Output is correct
39 Correct 136 ms 1556 KB Output is correct
40 Correct 25 ms 1588 KB Output is correct
41 Correct 26 ms 1564 KB Output is correct
42 Correct 25 ms 1560 KB Output is correct
43 Correct 25 ms 1588 KB Output is correct
44 Correct 26 ms 1612 KB Output is correct
45 Correct 25 ms 1552 KB Output is correct
46 Correct 132 ms 1556 KB Output is correct
47 Correct 125 ms 1560 KB Output is correct
48 Correct 127 ms 1568 KB Output is correct
49 Correct 123 ms 1564 KB Output is correct
50 Correct 125 ms 1604 KB Output is correct
51 Correct 134 ms 1612 KB Output is correct
52 Correct 123 ms 1560 KB Output is correct
53 Correct 124 ms 1564 KB Output is correct
54 Correct 129 ms 1564 KB Output is correct
55 Correct 127 ms 1564 KB Output is correct
56 Correct 124 ms 1604 KB Output is correct
57 Correct 127 ms 1568 KB Output is correct
58 Correct 127 ms 1568 KB Output is correct
59 Correct 136 ms 1552 KB Output is correct
60 Correct 128 ms 1604 KB Output is correct
61 Correct 126 ms 1568 KB Output is correct
62 Correct 123 ms 1568 KB Output is correct
63 Correct 122 ms 1564 KB Output is correct
64 Correct 125 ms 1564 KB Output is correct
65 Correct 123 ms 1568 KB Output is correct