Submission #851246

# Submission time Handle Problem Language Result Execution time Memory
851246 2023-09-19T06:23:29 Z dosts Autobus (COCI22_autobus) C++14
70 / 70
142 ms 8388 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
//#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
const int N = 71;
const int inf = 1e9;
vector<pair<int,int>> edges[N];
void solve() {
	int n,m;
	cin >> n >> m;
	vector<vi> got(n+1,vi(n+1,inf));
	for (int i=1;i<=m;i++) {
		int a,b,c;
		cin >> a >> b >> c;
		if (got[b][a]<c) continue;
		got[b][a] = c;
	}
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=n;j++) {
			if (got[i][j] != inf) edges[i].pb({j,got[i][j]});
		}
	}
	int k,q;
	cin >> k >> q;
	k = min(k,70);
	int fw[n+1][n+1][k+1];
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=n;j++) {
			for (int kk=0;kk<=k;kk++) {
				fw[i][j][kk] = inf;				
			}
		}
	}
	F(i,n) fw[i][i][0] = 0;
	for (int steps = 1;steps<=k;steps++) {
		for (int i=1;i<=n;i++) {
			for (int j=1;j<=n;j++) {
				for (auto it : edges[j]) {
					fw[i][j][steps] = min(fw[i][j][steps],fw[i][it.first][steps-1]+it.second);
				}
			}
		}
	}
	for (int steps=1;steps<=k;steps++) {
		for (int i=1;i<=n;i++) {
			for (int j=1;j<=n;j++) fw[i][j][steps] = min(fw[i][j][steps],fw[i][j][steps-1]);
		}
	}
	while (q--) {
		int a,b;
		cin >> a >> b;
		cout << (fw[a][b][k]==inf?-1:fw[a][b][k]) << '\n';
	}
}    
 
 
 
 
                                
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
 
 
 
# 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 1 ms 344 KB Output is correct
5 Correct 0 ms 504 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 604 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 1 ms 344 KB Output is correct
5 Correct 0 ms 504 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 6 ms 1628 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 6 ms 1240 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 17 ms 1368 KB Output is correct
13 Correct 76 ms 464 KB Output is correct
14 Correct 71 ms 476 KB Output is correct
15 Correct 93 ms 1620 KB Output is correct
16 Correct 80 ms 6996 KB Output is correct
17 Correct 74 ms 6724 KB Output is correct
18 Correct 72 ms 6600 KB Output is correct
19 Correct 101 ms 8388 KB Output is correct
20 Correct 92 ms 7612 KB Output is correct
21 Correct 80 ms 6844 KB Output is correct
22 Correct 82 ms 7116 KB Output is correct
23 Correct 81 ms 6984 KB Output is correct
24 Correct 88 ms 7496 KB Output is correct
25 Correct 75 ms 6812 KB Output is correct
26 Correct 80 ms 7220 KB Output is correct
27 Correct 83 ms 7248 KB Output is correct
28 Correct 81 ms 7248 KB Output is correct
29 Correct 77 ms 6720 KB Output is correct
30 Correct 82 ms 6724 KB Output is correct
31 Correct 95 ms 7620 KB Output is correct
32 Correct 101 ms 7880 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 1 ms 344 KB Output is correct
5 Correct 0 ms 504 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 6 ms 1628 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 6 ms 1240 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 17 ms 1368 KB Output is correct
20 Correct 76 ms 464 KB Output is correct
21 Correct 71 ms 476 KB Output is correct
22 Correct 93 ms 1620 KB Output is correct
23 Correct 80 ms 6996 KB Output is correct
24 Correct 74 ms 6724 KB Output is correct
25 Correct 72 ms 6600 KB Output is correct
26 Correct 101 ms 8388 KB Output is correct
27 Correct 92 ms 7612 KB Output is correct
28 Correct 80 ms 6844 KB Output is correct
29 Correct 82 ms 7116 KB Output is correct
30 Correct 81 ms 6984 KB Output is correct
31 Correct 88 ms 7496 KB Output is correct
32 Correct 75 ms 6812 KB Output is correct
33 Correct 80 ms 7220 KB Output is correct
34 Correct 83 ms 7248 KB Output is correct
35 Correct 81 ms 7248 KB Output is correct
36 Correct 77 ms 6720 KB Output is correct
37 Correct 82 ms 6724 KB Output is correct
38 Correct 95 ms 7620 KB Output is correct
39 Correct 101 ms 7880 KB Output is correct
40 Correct 2 ms 856 KB Output is correct
41 Correct 6 ms 1880 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 9 ms 1920 KB Output is correct
44 Correct 5 ms 604 KB Output is correct
45 Correct 24 ms 1988 KB Output is correct
46 Correct 82 ms 6604 KB Output is correct
47 Correct 85 ms 7364 KB Output is correct
48 Correct 77 ms 6848 KB Output is correct
49 Correct 108 ms 8024 KB Output is correct
50 Correct 73 ms 6728 KB Output is correct
51 Correct 89 ms 7120 KB Output is correct
52 Correct 79 ms 6740 KB Output is correct
53 Correct 102 ms 8012 KB Output is correct
54 Correct 73 ms 6732 KB Output is correct
55 Correct 75 ms 6868 KB Output is correct
56 Correct 100 ms 8008 KB Output is correct
57 Correct 102 ms 8016 KB Output is correct
58 Correct 85 ms 6728 KB Output is correct
59 Correct 87 ms 7244 KB Output is correct
60 Correct 99 ms 7760 KB Output is correct
61 Correct 142 ms 8276 KB Output is correct
62 Correct 80 ms 6596 KB Output is correct
63 Correct 79 ms 6992 KB Output is correct
64 Correct 82 ms 7000 KB Output is correct
65 Correct 107 ms 8012 KB Output is correct