# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
864519 |
2023-10-23T07:04:10 Z |
maks007 |
Toll (BOI17_toll) |
C++14 |
|
3000 ms |
12340 KB |
// Bismi ALlah
#include "bits/stdc++.h"
using namespace std;
signed main () {
int n, m, k, query;
cin >> k >> n >> m >> query;
vector<pair <int,int>> g[n], revG[n];
for(int i = 0; i < m; i ++) {
int u, v;
cin >> u >> v;
int w;
cin >> w;
revG[v].push_back({u, w});
g[u].push_back({v, w});
}
priority_queue <pair <int,int>> q;
vector <int> dist(n, 1e9);
dist[0] = 0;
q.push({0, 0});
while(!q.empty()) {
int v = q.top().second, cur_d = q.top().first;
q.pop();
if(cur_d > dist[v]) continue;
for(auto [u, w] : g[v]) {
if(dist[u] > dist[v] + w) {
dist[u] = dist[v] + w;
q.push({-dist[u], u});
}
}
}
while(query --) {
int a, b;
cin >> a >> b;
int dp[n];
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] : revG[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:26:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | for(auto [u, w] : g[v]) {
| ^
toll.cpp:42:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | for(auto [u, w] : revG[i]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1498 ms |
6740 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 |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
536 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
430 ms |
7224 KB |
Output is correct |
9 |
Correct |
401 ms |
7044 KB |
Output is correct |
10 |
Correct |
336 ms |
3296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1080 ms |
6504 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 |
26 ms |
348 KB |
Output is correct |
8 |
Correct |
40 ms |
604 KB |
Output is correct |
9 |
Correct |
405 ms |
6492 KB |
Output is correct |
10 |
Correct |
2315 ms |
8420 KB |
Output is correct |
11 |
Correct |
1557 ms |
6608 KB |
Output is correct |
12 |
Correct |
414 ms |
6232 KB |
Output is correct |
13 |
Correct |
666 ms |
7508 KB |
Output is correct |
14 |
Correct |
442 ms |
5456 KB |
Output is correct |
15 |
Correct |
515 ms |
4440 KB |
Output is correct |
16 |
Correct |
520 ms |
4500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
508 KB |
Output is correct |
10 |
Correct |
37 ms |
6488 KB |
Output is correct |
11 |
Correct |
88 ms |
6228 KB |
Output is correct |
12 |
Correct |
125 ms |
8136 KB |
Output is correct |
13 |
Correct |
141 ms |
8484 KB |
Output is correct |
14 |
Correct |
116 ms |
7128 KB |
Output is correct |
15 |
Correct |
71 ms |
4848 KB |
Output is correct |
16 |
Correct |
72 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
508 KB |
Output is correct |
10 |
Correct |
37 ms |
6488 KB |
Output is correct |
11 |
Correct |
88 ms |
6228 KB |
Output is correct |
12 |
Correct |
125 ms |
8136 KB |
Output is correct |
13 |
Correct |
141 ms |
8484 KB |
Output is correct |
14 |
Correct |
116 ms |
7128 KB |
Output is correct |
15 |
Correct |
71 ms |
4848 KB |
Output is correct |
16 |
Correct |
72 ms |
4432 KB |
Output is correct |
17 |
Correct |
706 ms |
6484 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 |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
8 ms |
344 KB |
Output is correct |
24 |
Correct |
15 ms |
600 KB |
Output is correct |
25 |
Correct |
21 ms |
600 KB |
Output is correct |
26 |
Correct |
18 ms |
600 KB |
Output is correct |
27 |
Correct |
150 ms |
7004 KB |
Output is correct |
28 |
Correct |
904 ms |
10584 KB |
Output is correct |
29 |
Correct |
896 ms |
10836 KB |
Output is correct |
30 |
Correct |
530 ms |
9180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1498 ms |
6740 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 |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
536 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
430 ms |
7224 KB |
Output is correct |
9 |
Correct |
401 ms |
7044 KB |
Output is correct |
10 |
Correct |
336 ms |
3296 KB |
Output is correct |
11 |
Correct |
1080 ms |
6504 KB |
Output is correct |
12 |
Correct |
0 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 |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
26 ms |
348 KB |
Output is correct |
18 |
Correct |
40 ms |
604 KB |
Output is correct |
19 |
Correct |
405 ms |
6492 KB |
Output is correct |
20 |
Correct |
2315 ms |
8420 KB |
Output is correct |
21 |
Correct |
1557 ms |
6608 KB |
Output is correct |
22 |
Correct |
414 ms |
6232 KB |
Output is correct |
23 |
Correct |
666 ms |
7508 KB |
Output is correct |
24 |
Correct |
442 ms |
5456 KB |
Output is correct |
25 |
Correct |
515 ms |
4440 KB |
Output is correct |
26 |
Correct |
520 ms |
4500 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
600 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
4 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
37 ms |
6488 KB |
Output is correct |
37 |
Correct |
88 ms |
6228 KB |
Output is correct |
38 |
Correct |
125 ms |
8136 KB |
Output is correct |
39 |
Correct |
141 ms |
8484 KB |
Output is correct |
40 |
Correct |
116 ms |
7128 KB |
Output is correct |
41 |
Correct |
71 ms |
4848 KB |
Output is correct |
42 |
Correct |
72 ms |
4432 KB |
Output is correct |
43 |
Correct |
706 ms |
6484 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 |
344 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
8 ms |
344 KB |
Output is correct |
50 |
Correct |
15 ms |
600 KB |
Output is correct |
51 |
Correct |
21 ms |
600 KB |
Output is correct |
52 |
Correct |
18 ms |
600 KB |
Output is correct |
53 |
Correct |
150 ms |
7004 KB |
Output is correct |
54 |
Correct |
904 ms |
10584 KB |
Output is correct |
55 |
Correct |
896 ms |
10836 KB |
Output is correct |
56 |
Correct |
530 ms |
9180 KB |
Output is correct |
57 |
Execution timed out |
3006 ms |
12340 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |