Submission #1018590

# Submission time Handle Problem Language Result Execution time Memory
1018590 2024-07-10T07:15:39 Z vjudge1 Autobus (COCI22_autobus) C++17
70 / 70
145 ms 9808 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 68 ms 3420 KB Output is correct
2 Correct 62 ms 3416 KB Output is correct
3 Correct 65 ms 3416 KB Output is correct
4 Correct 65 ms 3420 KB Output is correct
5 Correct 63 ms 3420 KB Output is correct
6 Correct 65 ms 3416 KB Output is correct
7 Correct 67 ms 3472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 63 ms 3428 KB Output is correct
8 Correct 68 ms 3420 KB Output is correct
9 Correct 64 ms 3416 KB Output is correct
10 Correct 85 ms 3432 KB Output is correct
11 Correct 74 ms 3420 KB Output is correct
12 Correct 63 ms 3416 KB Output is correct
13 Correct 136 ms 9300 KB Output is correct
14 Correct 135 ms 9548 KB Output is correct
15 Correct 135 ms 9556 KB Output is correct
16 Correct 135 ms 9428 KB Output is correct
17 Correct 140 ms 9560 KB Output is correct
18 Correct 127 ms 9808 KB Output is correct
19 Correct 125 ms 9552 KB Output is correct
20 Correct 134 ms 9552 KB Output is correct
21 Correct 129 ms 9684 KB Output is correct
22 Correct 137 ms 9556 KB Output is correct
23 Correct 129 ms 9556 KB Output is correct
24 Correct 131 ms 9556 KB Output is correct
25 Correct 128 ms 9548 KB Output is correct
26 Correct 136 ms 9564 KB Output is correct
27 Correct 136 ms 9680 KB Output is correct
28 Correct 130 ms 9556 KB Output is correct
29 Correct 133 ms 9296 KB Output is correct
30 Correct 133 ms 9300 KB Output is correct
31 Correct 134 ms 9420 KB Output is correct
32 Correct 130 ms 9440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 68 ms 3420 KB Output is correct
8 Correct 62 ms 3416 KB Output is correct
9 Correct 65 ms 3416 KB Output is correct
10 Correct 65 ms 3420 KB Output is correct
11 Correct 63 ms 3420 KB Output is correct
12 Correct 65 ms 3416 KB Output is correct
13 Correct 67 ms 3472 KB Output is correct
14 Correct 63 ms 3428 KB Output is correct
15 Correct 68 ms 3420 KB Output is correct
16 Correct 64 ms 3416 KB Output is correct
17 Correct 85 ms 3432 KB Output is correct
18 Correct 74 ms 3420 KB Output is correct
19 Correct 63 ms 3416 KB Output is correct
20 Correct 136 ms 9300 KB Output is correct
21 Correct 135 ms 9548 KB Output is correct
22 Correct 135 ms 9556 KB Output is correct
23 Correct 135 ms 9428 KB Output is correct
24 Correct 140 ms 9560 KB Output is correct
25 Correct 127 ms 9808 KB Output is correct
26 Correct 125 ms 9552 KB Output is correct
27 Correct 134 ms 9552 KB Output is correct
28 Correct 129 ms 9684 KB Output is correct
29 Correct 137 ms 9556 KB Output is correct
30 Correct 129 ms 9556 KB Output is correct
31 Correct 131 ms 9556 KB Output is correct
32 Correct 128 ms 9548 KB Output is correct
33 Correct 136 ms 9564 KB Output is correct
34 Correct 136 ms 9680 KB Output is correct
35 Correct 130 ms 9556 KB Output is correct
36 Correct 133 ms 9296 KB Output is correct
37 Correct 133 ms 9300 KB Output is correct
38 Correct 134 ms 9420 KB Output is correct
39 Correct 130 ms 9440 KB Output is correct
40 Correct 70 ms 3416 KB Output is correct
41 Correct 66 ms 3672 KB Output is correct
42 Correct 67 ms 3420 KB Output is correct
43 Correct 83 ms 3416 KB Output is correct
44 Correct 84 ms 3416 KB Output is correct
45 Correct 69 ms 3420 KB Output is correct
46 Correct 132 ms 9552 KB Output is correct
47 Correct 127 ms 9556 KB Output is correct
48 Correct 132 ms 9552 KB Output is correct
49 Correct 125 ms 9436 KB Output is correct
50 Correct 128 ms 9424 KB Output is correct
51 Correct 132 ms 9560 KB Output is correct
52 Correct 132 ms 9552 KB Output is correct
53 Correct 135 ms 9564 KB Output is correct
54 Correct 129 ms 9552 KB Output is correct
55 Correct 135 ms 9556 KB Output is correct
56 Correct 129 ms 9456 KB Output is correct
57 Correct 143 ms 9552 KB Output is correct
58 Correct 134 ms 9556 KB Output is correct
59 Correct 139 ms 9568 KB Output is correct
60 Correct 128 ms 9680 KB Output is correct
61 Correct 140 ms 9672 KB Output is correct
62 Correct 129 ms 9296 KB Output is correct
63 Correct 130 ms 9296 KB Output is correct
64 Correct 139 ms 9420 KB Output is correct
65 Correct 145 ms 9296 KB Output is correct