# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1052809 |
2024-08-11T01:17:34 Z |
gyg |
Toll (BOI17_toll) |
C++17 |
|
3000 ms |
109564 KB |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int MAX_N = 5e4 + 5, SQRT = 1e2, INF = 1e9;
int k, n, m, q;
array<vector<pii>, MAX_N> adj;
unordered_map<int, int> dist;
unordered_set<int> seen;
priority_queue<pii, vector<pii>, greater<pii>> order;
void dijk(int s, bool halt = false) {
dist.clear(), seen.clear();
dist[s] = 0, order.push({0, s});
while (order.size()) {
int u = order.top().second;
order.pop();
if (halt && (u / k) % SQRT == 0) continue;
if (seen.count(u)) continue;
seen.insert(u);
for (pii x : adj[u]) {
int new_dist = dist[u] + x.second;
if (dist.count(x.first) && new_dist >= dist[x.first]) continue;
dist[x.first] = new_dist;
order.push({new_dist, x.first});
}
}
}
unordered_map<int, array<int, MAX_N>> sp;
void precomp() {
for (int u = 0; u < n; u++) {
if ((u / k) % SQRT != 0) continue;
dijk(u);
for (int v = 0; v < n; v++)
sp[u][v] = (dist.count(v)) ? dist[v] : INF;
}
}
int comp(int s, int f) {
dijk(s, true);
int ans = INF;
if (dist.count(f)) ans = min(ans, dist[f]);
for (pii x : dist)
if ((x.first / k) % SQRT == 0)
ans = min(ans, x.second + sp[x.first][f]);
return ans;
}
int main() {
// freopen("toll.in", "r", stdin);
cin >> k >> n >> m >> q;
for (int i = 1; i <= m; i++) {
int u, v, w; cin >> u >> v >> w;
adj[u].push_back({v, w});
}
precomp();
for (int i = 1; i <= q; i++) {
int s, f; cin >> s >> f;
int ans = comp(s, f);
cout << ((ans >= INF) ? -1 : ans) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1694 ms |
106504 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
4 ms |
3420 KB |
Output is correct |
6 |
Correct |
4 ms |
3576 KB |
Output is correct |
7 |
Correct |
4 ms |
3676 KB |
Output is correct |
8 |
Correct |
239 ms |
102484 KB |
Output is correct |
9 |
Correct |
206 ms |
102056 KB |
Output is correct |
10 |
Correct |
147 ms |
99924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1129 ms |
104376 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
1 ms |
1884 KB |
Output is correct |
4 |
Correct |
1 ms |
2140 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
14 ms |
3716 KB |
Output is correct |
8 |
Correct |
16 ms |
3800 KB |
Output is correct |
9 |
Correct |
213 ms |
102476 KB |
Output is correct |
10 |
Correct |
2617 ms |
106724 KB |
Output is correct |
11 |
Correct |
2232 ms |
107048 KB |
Output is correct |
12 |
Correct |
209 ms |
102628 KB |
Output is correct |
13 |
Correct |
1207 ms |
68012 KB |
Output is correct |
14 |
Correct |
957 ms |
65800 KB |
Output is correct |
15 |
Correct |
832 ms |
64216 KB |
Output is correct |
16 |
Correct |
839 ms |
64240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
2124 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
4 ms |
3736 KB |
Output is correct |
8 |
Correct |
9 ms |
3676 KB |
Output is correct |
9 |
Correct |
7 ms |
3932 KB |
Output is correct |
10 |
Correct |
209 ms |
102484 KB |
Output is correct |
11 |
Correct |
1991 ms |
106868 KB |
Output is correct |
12 |
Correct |
2405 ms |
108512 KB |
Output is correct |
13 |
Correct |
2558 ms |
108932 KB |
Output is correct |
14 |
Correct |
2077 ms |
105840 KB |
Output is correct |
15 |
Correct |
805 ms |
63812 KB |
Output is correct |
16 |
Correct |
819 ms |
64012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
2124 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
4 ms |
3736 KB |
Output is correct |
8 |
Correct |
9 ms |
3676 KB |
Output is correct |
9 |
Correct |
7 ms |
3932 KB |
Output is correct |
10 |
Correct |
209 ms |
102484 KB |
Output is correct |
11 |
Correct |
1991 ms |
106868 KB |
Output is correct |
12 |
Correct |
2405 ms |
108512 KB |
Output is correct |
13 |
Correct |
2558 ms |
108932 KB |
Output is correct |
14 |
Correct |
2077 ms |
105840 KB |
Output is correct |
15 |
Correct |
805 ms |
63812 KB |
Output is correct |
16 |
Correct |
819 ms |
64012 KB |
Output is correct |
17 |
Correct |
2003 ms |
105308 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
1884 KB |
Output is correct |
20 |
Correct |
1 ms |
2140 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
10 ms |
3676 KB |
Output is correct |
24 |
Correct |
30 ms |
3676 KB |
Output is correct |
25 |
Correct |
136 ms |
3676 KB |
Output is correct |
26 |
Correct |
82 ms |
3932 KB |
Output is correct |
27 |
Correct |
204 ms |
102484 KB |
Output is correct |
28 |
Correct |
2603 ms |
108608 KB |
Output is correct |
29 |
Correct |
2745 ms |
108904 KB |
Output is correct |
30 |
Correct |
1258 ms |
105212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1694 ms |
106504 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
4 ms |
3420 KB |
Output is correct |
6 |
Correct |
4 ms |
3576 KB |
Output is correct |
7 |
Correct |
4 ms |
3676 KB |
Output is correct |
8 |
Correct |
239 ms |
102484 KB |
Output is correct |
9 |
Correct |
206 ms |
102056 KB |
Output is correct |
10 |
Correct |
147 ms |
99924 KB |
Output is correct |
11 |
Correct |
1129 ms |
104376 KB |
Output is correct |
12 |
Correct |
1 ms |
1624 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
1 ms |
2140 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
14 ms |
3716 KB |
Output is correct |
18 |
Correct |
16 ms |
3800 KB |
Output is correct |
19 |
Correct |
213 ms |
102476 KB |
Output is correct |
20 |
Correct |
2617 ms |
106724 KB |
Output is correct |
21 |
Correct |
2232 ms |
107048 KB |
Output is correct |
22 |
Correct |
209 ms |
102628 KB |
Output is correct |
23 |
Correct |
1207 ms |
68012 KB |
Output is correct |
24 |
Correct |
957 ms |
65800 KB |
Output is correct |
25 |
Correct |
832 ms |
64216 KB |
Output is correct |
26 |
Correct |
839 ms |
64240 KB |
Output is correct |
27 |
Correct |
1 ms |
1628 KB |
Output is correct |
28 |
Correct |
1 ms |
1884 KB |
Output is correct |
29 |
Correct |
1 ms |
2124 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
3420 KB |
Output is correct |
33 |
Correct |
4 ms |
3736 KB |
Output is correct |
34 |
Correct |
9 ms |
3676 KB |
Output is correct |
35 |
Correct |
7 ms |
3932 KB |
Output is correct |
36 |
Correct |
209 ms |
102484 KB |
Output is correct |
37 |
Correct |
1991 ms |
106868 KB |
Output is correct |
38 |
Correct |
2405 ms |
108512 KB |
Output is correct |
39 |
Correct |
2558 ms |
108932 KB |
Output is correct |
40 |
Correct |
2077 ms |
105840 KB |
Output is correct |
41 |
Correct |
805 ms |
63812 KB |
Output is correct |
42 |
Correct |
819 ms |
64012 KB |
Output is correct |
43 |
Correct |
2003 ms |
105308 KB |
Output is correct |
44 |
Correct |
1 ms |
1628 KB |
Output is correct |
45 |
Correct |
1 ms |
1884 KB |
Output is correct |
46 |
Correct |
1 ms |
2140 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
10 ms |
3676 KB |
Output is correct |
50 |
Correct |
30 ms |
3676 KB |
Output is correct |
51 |
Correct |
136 ms |
3676 KB |
Output is correct |
52 |
Correct |
82 ms |
3932 KB |
Output is correct |
53 |
Correct |
204 ms |
102484 KB |
Output is correct |
54 |
Correct |
2603 ms |
108608 KB |
Output is correct |
55 |
Correct |
2745 ms |
108904 KB |
Output is correct |
56 |
Correct |
1258 ms |
105212 KB |
Output is correct |
57 |
Execution timed out |
3077 ms |
109564 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |