Submission #864536

# Submission time Handle Problem Language Result Execution time Memory
864536 2023-10-23T07:32:07 Z maks007 Toll (BOI17_toll) C++14
56 / 100
3000 ms 6400 KB
// Bismi ALlah
#include "bits/stdc++.h"
 
using namespace std;
 
signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, k, query;
	cin >> k >> n >> m >> query;
	vector<pair <int,int>> g[n];
	for(int i = 0; i < m; i ++) {
		int u, v;
		cin >> u >> v;
		int w;
		cin >> w;
		g[v].push_back({u, w});
	}
	int dp[n];
	while(query --) {
		int a, b;
		cin >> a >> b;
		
		for(int i = 0; i < n; i ++) dp[i] = 1e9;
		dp[b] = 0;
		for(int i = n - 1; i >= 0; i--) {
			if(dp[i] != 1e9) {
				for(auto [u, w] : g[i]) {
					dp[u] = min(dp[u], dp[i] + w);
				}
			}
		}
		if(dp[a] == 1e9) cout << -1 << "\n";
		else cout << dp[a] << "\n";
		
	}
	return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:28:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |     for(auto [u, w] : g[i]) {
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1397 ms 4408 KB Output is correct
2 Correct 1 ms 448 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 350 ms 3928 KB Output is correct
9 Correct 346 ms 4160 KB Output is correct
10 Correct 318 ms 1944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 951 ms 4388 KB Output is correct
2 Correct 1 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 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 10 ms 584 KB Output is correct
8 Correct 23 ms 624 KB Output is correct
9 Correct 385 ms 4132 KB Output is correct
10 Correct 2241 ms 5768 KB Output is correct
11 Correct 1577 ms 4652 KB Output is correct
12 Correct 340 ms 4324 KB Output is correct
13 Correct 549 ms 5712 KB Output is correct
14 Correct 411 ms 3932 KB Output is correct
15 Correct 446 ms 3344 KB Output is correct
16 Correct 433 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 16 ms 3932 KB Output is correct
11 Correct 48 ms 4176 KB Output is correct
12 Correct 56 ms 5456 KB Output is correct
13 Correct 58 ms 5964 KB Output is correct
14 Correct 55 ms 4972 KB Output is correct
15 Correct 43 ms 3164 KB Output is correct
16 Correct 34 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 16 ms 3932 KB Output is correct
11 Correct 48 ms 4176 KB Output is correct
12 Correct 56 ms 5456 KB Output is correct
13 Correct 58 ms 5964 KB Output is correct
14 Correct 55 ms 4972 KB Output is correct
15 Correct 43 ms 3164 KB Output is correct
16 Correct 34 ms 3160 KB Output is correct
17 Correct 651 ms 4628 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 9 ms 348 KB Output is correct
25 Correct 14 ms 604 KB Output is correct
26 Correct 12 ms 608 KB Output is correct
27 Correct 114 ms 3928 KB Output is correct
28 Correct 820 ms 5724 KB Output is correct
29 Correct 795 ms 6224 KB Output is correct
30 Correct 432 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1397 ms 4408 KB Output is correct
2 Correct 1 ms 448 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 350 ms 3928 KB Output is correct
9 Correct 346 ms 4160 KB Output is correct
10 Correct 318 ms 1944 KB Output is correct
11 Correct 951 ms 4388 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 10 ms 584 KB Output is correct
18 Correct 23 ms 624 KB Output is correct
19 Correct 385 ms 4132 KB Output is correct
20 Correct 2241 ms 5768 KB Output is correct
21 Correct 1577 ms 4652 KB Output is correct
22 Correct 340 ms 4324 KB Output is correct
23 Correct 549 ms 5712 KB Output is correct
24 Correct 411 ms 3932 KB Output is correct
25 Correct 446 ms 3344 KB Output is correct
26 Correct 433 ms 3160 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 16 ms 3932 KB Output is correct
37 Correct 48 ms 4176 KB Output is correct
38 Correct 56 ms 5456 KB Output is correct
39 Correct 58 ms 5964 KB Output is correct
40 Correct 55 ms 4972 KB Output is correct
41 Correct 43 ms 3164 KB Output is correct
42 Correct 34 ms 3160 KB Output is correct
43 Correct 651 ms 4628 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 600 KB Output is correct
49 Correct 5 ms 348 KB Output is correct
50 Correct 9 ms 348 KB Output is correct
51 Correct 14 ms 604 KB Output is correct
52 Correct 12 ms 608 KB Output is correct
53 Correct 114 ms 3928 KB Output is correct
54 Correct 820 ms 5724 KB Output is correct
55 Correct 795 ms 6224 KB Output is correct
56 Correct 432 ms 4944 KB Output is correct
57 Execution timed out 3016 ms 6400 KB Time limit exceeded
58 Halted 0 ms 0 KB -