Submission #1018968

# Submission time Handle Problem Language Result Execution time Memory
1018968 2024-07-10T11:22:38 Z aeg Autobus (COCI22_autobus) C++17
70 / 70
171 ms 3544 KB
#include <bits/stdc++.h>
using namespace std;

#define int int64_t


int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> adj(n, vector<int>(n, INT_MAX));
	while(m --) {
		int a, b, t;
		cin >> a >> b >> t;
		a --; b--;
		adj[a][b] = min(adj[a][b], t);
	}
	vector<vector<vector<int>>> dp(n, vector<vector<int>> (n, vector<int> (n, INT_MAX)));
	for(int i = 0; i < n; i ++) dp[i][i][0] = 0;
	for(int i = 0; i < n; i ++) for(int j = 0; j < n; j ++) dp[i][j][1] = adj[i][j];
	for(int k = 1; k < n; k ++) {
		for(int i = 0; i < n; i ++) {
			for(int j = 0; j < n; j ++) {
				for(int t = 0; t < n; t ++) {
					dp[i][j][k] = min(dp[i][t][k - 1] + dp[t][j][1], dp[i][j][k]);
				}
			}
		}
	}
	int k, q;
	cin >> k >> q;
	while(q--) {
		int c, d;
		cin >> c >> d;
		int ans = INT_MAX;
		c --; d--;
		for(int i = 0; i < min(n, k + 1); i ++) {
			ans = min(ans, dp[c][d][i]);
		}
		if(ans == INT_MAX) ans = -1;
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 3396 KB Output is correct
2 Correct 84 ms 3408 KB Output is correct
3 Correct 67 ms 3392 KB Output is correct
4 Correct 63 ms 3164 KB Output is correct
5 Correct 73 ms 3160 KB Output is correct
6 Correct 67 ms 3392 KB Output is correct
7 Correct 66 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 71 ms 3408 KB Output is correct
8 Correct 71 ms 3392 KB Output is correct
9 Correct 69 ms 3392 KB Output is correct
10 Correct 66 ms 3164 KB Output is correct
11 Correct 67 ms 3160 KB Output is correct
12 Correct 76 ms 3164 KB Output is correct
13 Correct 131 ms 3288 KB Output is correct
14 Correct 127 ms 3152 KB Output is correct
15 Correct 124 ms 3152 KB Output is correct
16 Correct 128 ms 3300 KB Output is correct
17 Correct 136 ms 3304 KB Output is correct
18 Correct 127 ms 3304 KB Output is correct
19 Correct 126 ms 3152 KB Output is correct
20 Correct 126 ms 3396 KB Output is correct
21 Correct 128 ms 3412 KB Output is correct
22 Correct 127 ms 3288 KB Output is correct
23 Correct 159 ms 3308 KB Output is correct
24 Correct 126 ms 3388 KB Output is correct
25 Correct 129 ms 3308 KB Output is correct
26 Correct 126 ms 3156 KB Output is correct
27 Correct 129 ms 3296 KB Output is correct
28 Correct 134 ms 3400 KB Output is correct
29 Correct 124 ms 3304 KB Output is correct
30 Correct 123 ms 3296 KB Output is correct
31 Correct 143 ms 3304 KB Output is correct
32 Correct 128 ms 3288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 66 ms 3396 KB Output is correct
8 Correct 84 ms 3408 KB Output is correct
9 Correct 67 ms 3392 KB Output is correct
10 Correct 63 ms 3164 KB Output is correct
11 Correct 73 ms 3160 KB Output is correct
12 Correct 67 ms 3392 KB Output is correct
13 Correct 66 ms 3160 KB Output is correct
14 Correct 71 ms 3408 KB Output is correct
15 Correct 71 ms 3392 KB Output is correct
16 Correct 69 ms 3392 KB Output is correct
17 Correct 66 ms 3164 KB Output is correct
18 Correct 67 ms 3160 KB Output is correct
19 Correct 76 ms 3164 KB Output is correct
20 Correct 131 ms 3288 KB Output is correct
21 Correct 127 ms 3152 KB Output is correct
22 Correct 124 ms 3152 KB Output is correct
23 Correct 128 ms 3300 KB Output is correct
24 Correct 136 ms 3304 KB Output is correct
25 Correct 127 ms 3304 KB Output is correct
26 Correct 126 ms 3152 KB Output is correct
27 Correct 126 ms 3396 KB Output is correct
28 Correct 128 ms 3412 KB Output is correct
29 Correct 127 ms 3288 KB Output is correct
30 Correct 159 ms 3308 KB Output is correct
31 Correct 126 ms 3388 KB Output is correct
32 Correct 129 ms 3308 KB Output is correct
33 Correct 126 ms 3156 KB Output is correct
34 Correct 129 ms 3296 KB Output is correct
35 Correct 134 ms 3400 KB Output is correct
36 Correct 124 ms 3304 KB Output is correct
37 Correct 123 ms 3296 KB Output is correct
38 Correct 143 ms 3304 KB Output is correct
39 Correct 128 ms 3288 KB Output is correct
40 Correct 66 ms 3420 KB Output is correct
41 Correct 68 ms 3408 KB Output is correct
42 Correct 66 ms 3164 KB Output is correct
43 Correct 70 ms 3164 KB Output is correct
44 Correct 69 ms 3160 KB Output is correct
45 Correct 72 ms 3164 KB Output is correct
46 Correct 128 ms 3288 KB Output is correct
47 Correct 171 ms 3152 KB Output is correct
48 Correct 127 ms 3304 KB Output is correct
49 Correct 148 ms 3304 KB Output is correct
50 Correct 125 ms 3152 KB Output is correct
51 Correct 128 ms 3152 KB Output is correct
52 Correct 125 ms 3156 KB Output is correct
53 Correct 129 ms 3152 KB Output is correct
54 Correct 122 ms 3408 KB Output is correct
55 Correct 126 ms 3408 KB Output is correct
56 Correct 121 ms 3412 KB Output is correct
57 Correct 127 ms 3300 KB Output is correct
58 Correct 131 ms 3156 KB Output is correct
59 Correct 128 ms 3304 KB Output is correct
60 Correct 123 ms 3304 KB Output is correct
61 Correct 133 ms 3544 KB Output is correct
62 Correct 122 ms 3392 KB Output is correct
63 Correct 125 ms 3288 KB Output is correct
64 Correct 128 ms 3288 KB Output is correct
65 Correct 128 ms 3304 KB Output is correct