# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
641266 |
2022-09-16T09:42:58 Z |
lto5 |
Autobus (COCI22_autobus) |
C++14 |
|
128 ms |
9932 KB |
#include <bits/stdc++.h>
using namespace std;
long long dist[75][75];
long long f[75][75][75];
int n, m;
int lim, q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
memset(dist, 0x3f, sizeof(dist));
memset(f, 0x3f, sizeof(f));
const long long INF = dist[0][0];
for (int i = 0; i <= n; i++)
dist[i][i] = 0,
f[1][i][i] = 0;
while (m--) {
int u, v, w;
cin >> u >> v >> w;
dist[u][v] = min(dist[u][v], 1ll * w);
f[1][u][v] = dist[u][v];
}
cin >> lim >> q;
lim = min(lim, n-1);
for (int t = 2; t <= lim; t++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++)
f[t][i][j] = min(f[t][i][j], f[t - 1][i][k] + dist[k][j]);
}
}
}
while (q--) {
int u, v;
cin >> u >> v;
long long ans = INF;
for (int t = 0; t <= lim; t++)
ans = min(ans, f[t][u][v]);
if (ans == INF)
cout << -1 << "\n";
else cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
Output is correct |
2 |
Correct |
2 ms |
3668 KB |
Output is correct |
3 |
Correct |
2 ms |
3668 KB |
Output is correct |
4 |
Correct |
2 ms |
3540 KB |
Output is correct |
5 |
Correct |
2 ms |
3668 KB |
Output is correct |
6 |
Correct |
2 ms |
3656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3668 KB |
Output is correct |
2 |
Correct |
4 ms |
3668 KB |
Output is correct |
3 |
Correct |
5 ms |
3668 KB |
Output is correct |
4 |
Correct |
4 ms |
3668 KB |
Output is correct |
5 |
Correct |
4 ms |
3672 KB |
Output is correct |
6 |
Correct |
5 ms |
3744 KB |
Output is correct |
7 |
Correct |
5 ms |
3740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
Output is correct |
2 |
Correct |
2 ms |
3668 KB |
Output is correct |
3 |
Correct |
2 ms |
3668 KB |
Output is correct |
4 |
Correct |
2 ms |
3540 KB |
Output is correct |
5 |
Correct |
2 ms |
3668 KB |
Output is correct |
6 |
Correct |
2 ms |
3656 KB |
Output is correct |
7 |
Correct |
12 ms |
3668 KB |
Output is correct |
8 |
Correct |
29 ms |
3684 KB |
Output is correct |
9 |
Correct |
4 ms |
3668 KB |
Output is correct |
10 |
Correct |
18 ms |
3708 KB |
Output is correct |
11 |
Correct |
9 ms |
3668 KB |
Output is correct |
12 |
Correct |
21 ms |
3788 KB |
Output is correct |
13 |
Correct |
105 ms |
9772 KB |
Output is correct |
14 |
Correct |
91 ms |
9776 KB |
Output is correct |
15 |
Correct |
112 ms |
9676 KB |
Output is correct |
16 |
Correct |
100 ms |
9776 KB |
Output is correct |
17 |
Correct |
94 ms |
9804 KB |
Output is correct |
18 |
Correct |
114 ms |
9776 KB |
Output is correct |
19 |
Correct |
116 ms |
9904 KB |
Output is correct |
20 |
Correct |
103 ms |
9776 KB |
Output is correct |
21 |
Correct |
99 ms |
9904 KB |
Output is correct |
22 |
Correct |
98 ms |
9900 KB |
Output is correct |
23 |
Correct |
96 ms |
9904 KB |
Output is correct |
24 |
Correct |
107 ms |
9904 KB |
Output is correct |
25 |
Correct |
95 ms |
9900 KB |
Output is correct |
26 |
Correct |
128 ms |
9916 KB |
Output is correct |
27 |
Correct |
102 ms |
9904 KB |
Output is correct |
28 |
Correct |
98 ms |
9932 KB |
Output is correct |
29 |
Correct |
96 ms |
9664 KB |
Output is correct |
30 |
Correct |
118 ms |
9648 KB |
Output is correct |
31 |
Correct |
109 ms |
9648 KB |
Output is correct |
32 |
Correct |
113 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
Output is correct |
2 |
Correct |
2 ms |
3668 KB |
Output is correct |
3 |
Correct |
2 ms |
3668 KB |
Output is correct |
4 |
Correct |
2 ms |
3540 KB |
Output is correct |
5 |
Correct |
2 ms |
3668 KB |
Output is correct |
6 |
Correct |
2 ms |
3656 KB |
Output is correct |
7 |
Correct |
3 ms |
3668 KB |
Output is correct |
8 |
Correct |
4 ms |
3668 KB |
Output is correct |
9 |
Correct |
5 ms |
3668 KB |
Output is correct |
10 |
Correct |
4 ms |
3668 KB |
Output is correct |
11 |
Correct |
4 ms |
3672 KB |
Output is correct |
12 |
Correct |
5 ms |
3744 KB |
Output is correct |
13 |
Correct |
5 ms |
3740 KB |
Output is correct |
14 |
Correct |
12 ms |
3668 KB |
Output is correct |
15 |
Correct |
29 ms |
3684 KB |
Output is correct |
16 |
Correct |
4 ms |
3668 KB |
Output is correct |
17 |
Correct |
18 ms |
3708 KB |
Output is correct |
18 |
Correct |
9 ms |
3668 KB |
Output is correct |
19 |
Correct |
21 ms |
3788 KB |
Output is correct |
20 |
Correct |
105 ms |
9772 KB |
Output is correct |
21 |
Correct |
91 ms |
9776 KB |
Output is correct |
22 |
Correct |
112 ms |
9676 KB |
Output is correct |
23 |
Correct |
100 ms |
9776 KB |
Output is correct |
24 |
Correct |
94 ms |
9804 KB |
Output is correct |
25 |
Correct |
114 ms |
9776 KB |
Output is correct |
26 |
Correct |
116 ms |
9904 KB |
Output is correct |
27 |
Correct |
103 ms |
9776 KB |
Output is correct |
28 |
Correct |
99 ms |
9904 KB |
Output is correct |
29 |
Correct |
98 ms |
9900 KB |
Output is correct |
30 |
Correct |
96 ms |
9904 KB |
Output is correct |
31 |
Correct |
107 ms |
9904 KB |
Output is correct |
32 |
Correct |
95 ms |
9900 KB |
Output is correct |
33 |
Correct |
128 ms |
9916 KB |
Output is correct |
34 |
Correct |
102 ms |
9904 KB |
Output is correct |
35 |
Correct |
98 ms |
9932 KB |
Output is correct |
36 |
Correct |
96 ms |
9664 KB |
Output is correct |
37 |
Correct |
118 ms |
9648 KB |
Output is correct |
38 |
Correct |
109 ms |
9648 KB |
Output is correct |
39 |
Correct |
113 ms |
9676 KB |
Output is correct |
40 |
Correct |
9 ms |
3668 KB |
Output is correct |
41 |
Correct |
29 ms |
3696 KB |
Output is correct |
42 |
Correct |
6 ms |
3708 KB |
Output is correct |
43 |
Correct |
29 ms |
3696 KB |
Output is correct |
44 |
Correct |
7 ms |
3668 KB |
Output is correct |
45 |
Correct |
29 ms |
3748 KB |
Output is correct |
46 |
Correct |
98 ms |
9784 KB |
Output is correct |
47 |
Correct |
101 ms |
9776 KB |
Output is correct |
48 |
Correct |
94 ms |
9784 KB |
Output is correct |
49 |
Correct |
127 ms |
9784 KB |
Output is correct |
50 |
Correct |
96 ms |
9784 KB |
Output is correct |
51 |
Correct |
111 ms |
9864 KB |
Output is correct |
52 |
Correct |
113 ms |
9776 KB |
Output is correct |
53 |
Correct |
116 ms |
9788 KB |
Output is correct |
54 |
Correct |
92 ms |
9908 KB |
Output is correct |
55 |
Correct |
101 ms |
9916 KB |
Output is correct |
56 |
Correct |
126 ms |
9904 KB |
Output is correct |
57 |
Correct |
115 ms |
9900 KB |
Output is correct |
58 |
Correct |
104 ms |
9900 KB |
Output is correct |
59 |
Correct |
109 ms |
9904 KB |
Output is correct |
60 |
Correct |
118 ms |
9908 KB |
Output is correct |
61 |
Correct |
116 ms |
9904 KB |
Output is correct |
62 |
Correct |
92 ms |
9736 KB |
Output is correct |
63 |
Correct |
128 ms |
9672 KB |
Output is correct |
64 |
Correct |
105 ms |
9772 KB |
Output is correct |
65 |
Correct |
118 ms |
9656 KB |
Output is correct |