Submission #707587

# Submission time Handle Problem Language Result Execution time Memory
707587 2023-03-09T11:55:34 Z Trisanu_Das Autobus (COCI22_autobus) C++17
70 / 70
134 ms 8020 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
const int INF=1e9;
int n, m, k, q, d[70][70], dp[70][70][70];
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i=0; i<n; ++i)
		for (int j=0; j<n; ++j)
			d[i][j]=i==j?0:INF;
	for (int i=0; i<m; ++i) {
		int u, v, t;
		cin >> u >> v >> t, --u, --v;
		d[u][v]=min(d[u][v], t);
	}
	cin >> k >> q;
	k=min(k, n-1);
	memset(dp, 0x3f, sizeof(dp));
	for (int i=0; i<n; ++i)
		for (int j=0; j<n; ++j) {
			dp[0][i][j]=i==j?0:INF;
			dp[1][i][j]=d[i][j];
		}
	for (int i=2; i<=k; ++i)
		for (int a=0; a<n; ++a)
			for (int b=0; b<n; ++b)
				for (int c=0; c<n; ++c)
					dp[i][a][c]=min(dp[i][a][c], dp[i-1][a][b]+d[b][c]);
	while(q--) {
		int a, b;
		cin >> a >> b, --a, --b;
		cout << (dp[k][a][b]>=INF?-1:dp[k][a][b]) << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1840 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1652 KB Output is correct
6 Correct 1 ms 1608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1620 KB Output is correct
2 Correct 2 ms 1748 KB Output is correct
3 Correct 3 ms 1748 KB Output is correct
4 Correct 2 ms 1620 KB Output is correct
5 Correct 3 ms 1620 KB Output is correct
6 Correct 3 ms 1748 KB Output is correct
7 Correct 3 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1840 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1652 KB Output is correct
6 Correct 1 ms 1608 KB Output is correct
7 Correct 10 ms 1744 KB Output is correct
8 Correct 24 ms 1740 KB Output is correct
9 Correct 3 ms 1620 KB Output is correct
10 Correct 14 ms 1620 KB Output is correct
11 Correct 5 ms 1748 KB Output is correct
12 Correct 17 ms 1704 KB Output is correct
13 Correct 96 ms 7736 KB Output is correct
14 Correct 129 ms 7768 KB Output is correct
15 Correct 102 ms 7744 KB Output is correct
16 Correct 94 ms 7748 KB Output is correct
17 Correct 94 ms 7896 KB Output is correct
18 Correct 86 ms 7884 KB Output is correct
19 Correct 134 ms 7864 KB Output is correct
20 Correct 99 ms 7884 KB Output is correct
21 Correct 99 ms 7884 KB Output is correct
22 Correct 92 ms 7872 KB Output is correct
23 Correct 90 ms 7880 KB Output is correct
24 Correct 129 ms 7880 KB Output is correct
25 Correct 109 ms 8008 KB Output is correct
26 Correct 98 ms 8000 KB Output is correct
27 Correct 101 ms 8020 KB Output is correct
28 Correct 115 ms 7996 KB Output is correct
29 Correct 93 ms 7744 KB Output is correct
30 Correct 94 ms 7744 KB Output is correct
31 Correct 123 ms 7748 KB Output is correct
32 Correct 124 ms 7856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1840 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1652 KB Output is correct
6 Correct 1 ms 1608 KB Output is correct
7 Correct 2 ms 1620 KB Output is correct
8 Correct 2 ms 1748 KB Output is correct
9 Correct 3 ms 1748 KB Output is correct
10 Correct 2 ms 1620 KB Output is correct
11 Correct 3 ms 1620 KB Output is correct
12 Correct 3 ms 1748 KB Output is correct
13 Correct 3 ms 1748 KB Output is correct
14 Correct 10 ms 1744 KB Output is correct
15 Correct 24 ms 1740 KB Output is correct
16 Correct 3 ms 1620 KB Output is correct
17 Correct 14 ms 1620 KB Output is correct
18 Correct 5 ms 1748 KB Output is correct
19 Correct 17 ms 1704 KB Output is correct
20 Correct 96 ms 7736 KB Output is correct
21 Correct 129 ms 7768 KB Output is correct
22 Correct 102 ms 7744 KB Output is correct
23 Correct 94 ms 7748 KB Output is correct
24 Correct 94 ms 7896 KB Output is correct
25 Correct 86 ms 7884 KB Output is correct
26 Correct 134 ms 7864 KB Output is correct
27 Correct 99 ms 7884 KB Output is correct
28 Correct 99 ms 7884 KB Output is correct
29 Correct 92 ms 7872 KB Output is correct
30 Correct 90 ms 7880 KB Output is correct
31 Correct 129 ms 7880 KB Output is correct
32 Correct 109 ms 8008 KB Output is correct
33 Correct 98 ms 8000 KB Output is correct
34 Correct 101 ms 8020 KB Output is correct
35 Correct 115 ms 7996 KB Output is correct
36 Correct 93 ms 7744 KB Output is correct
37 Correct 94 ms 7744 KB Output is correct
38 Correct 123 ms 7748 KB Output is correct
39 Correct 124 ms 7856 KB Output is correct
40 Correct 11 ms 1720 KB Output is correct
41 Correct 25 ms 1740 KB Output is correct
42 Correct 5 ms 1616 KB Output is correct
43 Correct 24 ms 1716 KB Output is correct
44 Correct 6 ms 1764 KB Output is correct
45 Correct 35 ms 1752 KB Output is correct
46 Correct 91 ms 7740 KB Output is correct
47 Correct 106 ms 7940 KB Output is correct
48 Correct 96 ms 7748 KB Output is correct
49 Correct 122 ms 7748 KB Output is correct
50 Correct 91 ms 7868 KB Output is correct
51 Correct 93 ms 7880 KB Output is correct
52 Correct 113 ms 7868 KB Output is correct
53 Correct 116 ms 7888 KB Output is correct
54 Correct 92 ms 7876 KB Output is correct
55 Correct 91 ms 7872 KB Output is correct
56 Correct 126 ms 7880 KB Output is correct
57 Correct 117 ms 7872 KB Output is correct
58 Correct 101 ms 8012 KB Output is correct
59 Correct 99 ms 8004 KB Output is correct
60 Correct 121 ms 8012 KB Output is correct
61 Correct 110 ms 8012 KB Output is correct
62 Correct 123 ms 7752 KB Output is correct
63 Correct 103 ms 7744 KB Output is correct
64 Correct 98 ms 7760 KB Output is correct
65 Correct 107 ms 7736 KB Output is correct