#include "escape_route.h"
#include <bits/stdc++.h>
using namespace std;
vector<long long> calculate_necessary_time(int n, int m, long long S, int q, vector<int> A, vector<int> B, vector<long long> L, vector<long long> C, vector<int> U, vector<int> V, vector<long long> T) {
const long long INF = 4e18;
auto getTime = []() { return chrono::steady_clock::now().time_since_epoch().count(); };
double time0 = getTime();
vector<vector<pair<int, int>>> adj(n);
for (int i = 0; i < m; i++) {
int u = A[i];
int v = B[i];
adj[u].push_back({v, i});
adj[v].push_back({u, i});
}
auto [f, g] = [&]() -> pair<vector<vector<vector<long long>>>, vector<vector<long long>>> {
vector<vector<vector<long long>>> f(n);
vector<vector<long long>> g(n);
for (int source = 0; source < n; source++) {
long long t = 0;
while (true) {
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<>> pq;
vector<long long> dist(n, INF);
vector<int> par(n, -1);
dist[source] = 0;
pq.push({dist[source], source});
while (!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
if (d != dist[u]) continue;
for (auto [v, i] : adj[u]) {
if (t + dist[u] > C[i] - L[i]) continue;
if (dist[u] + L[i] < dist[v]) {
dist[v] = dist[u] + L[i];
par[v] = i;
pq.push({dist[v], v});
}
}
}
f[source].push_back(dist);
g[source].push_back(t);
long long new_t = INF;
for (int u = 0; u < n; u++) {
if (par[u] == -1) continue;
new_t = min(new_t, C[par[u]] - dist[u] + 1);
}
if (new_t >= S || new_t == t) break;
t = new_t;
}
}
return make_pair(f, g);
}();
vector<vector<long long>> dist = [&]() -> vector<vector<long long>> {
vector<vector<long long>> dist(n, vector<long long>(n, INF));
for (int u = 0; u < n; u++) {
for (int v = 0; v < n; v++) {
if (f[u][0][v] != INF) {
dist[u][v] = S;
}
}
}
for (int u = 0; u < n; u++) {
dist[u][u] = 0;
}
for (int w = 0; w < n; w++) {
for (int u = 0; u < n; u++) {
for (int v = 0; v < n; v++) {
dist[u][v] = min(dist[u][v], dist[u][w] + dist[w][v]);
}
}
}
vector<vector<long long>> true_dist = dist;
for (int u = 0; u < n; u++) {
for (int v = 0; v < n; v++) {
for (int w = 0; w < n; w++) {
if (f[w][0][v] != INF) {
true_dist[u][v] = min(true_dist[u][v], dist[u][w] + f[w][0][v]);
}
}
}
}
return true_dist;
}();
return [&]() -> vector<long long> {
vector<vector<vector<long long>>> memorize(n);
for (int u = 0; u < n; u++) {
memorize[u].resize(f[u].size(), vector<long long>(n, -1));
}
auto get = [&](int u, int v, long long t) -> long long {
if ((getTime() - time0) / 1e9 > 6) return -1;
int i = upper_bound(g[u].begin(), g[u].end(), t) - g[u].begin() - 1;
if (f[u][i][v] != INF) {
return f[u][i][v];
}
if (memorize[u][i][v] == -1) {
memorize[u][i][v] = INF;
for (int w = 0; w < n; w++) {
if (f[u][i][w] != INF) {
memorize[u][i][v] = min(memorize[u][i][v],dist[w][v]);
}
}
}
return memorize[u][i][v] + S - t;
};
vector<long long> res(q);
for (int i = 0; i < q; i++) {
res[i] = get(U[i], V[i], T[i]);
}
return res;
}();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
65192 KB |
Output is correct |
2 |
Correct |
17 ms |
65188 KB |
Output is correct |
3 |
Correct |
58 ms |
65164 KB |
Output is correct |
4 |
Correct |
16 ms |
65040 KB |
Output is correct |
5 |
Correct |
11 ms |
65112 KB |
Output is correct |
6 |
Correct |
15 ms |
65116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
713 ms |
166892 KB |
Output is correct |
2 |
Correct |
786 ms |
192784 KB |
Output is correct |
3 |
Correct |
375 ms |
155784 KB |
Output is correct |
4 |
Correct |
879 ms |
202180 KB |
Output is correct |
5 |
Correct |
876 ms |
201744 KB |
Output is correct |
6 |
Correct |
9 ms |
65116 KB |
Output is correct |
7 |
Correct |
375 ms |
155760 KB |
Output is correct |
8 |
Correct |
368 ms |
193916 KB |
Output is correct |
9 |
Correct |
588 ms |
155176 KB |
Output is correct |
10 |
Correct |
868 ms |
201872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
65192 KB |
Output is correct |
2 |
Correct |
17 ms |
65188 KB |
Output is correct |
3 |
Correct |
58 ms |
65164 KB |
Output is correct |
4 |
Correct |
16 ms |
65040 KB |
Output is correct |
5 |
Correct |
11 ms |
65112 KB |
Output is correct |
6 |
Correct |
15 ms |
65116 KB |
Output is correct |
7 |
Correct |
713 ms |
166892 KB |
Output is correct |
8 |
Correct |
786 ms |
192784 KB |
Output is correct |
9 |
Correct |
375 ms |
155784 KB |
Output is correct |
10 |
Correct |
879 ms |
202180 KB |
Output is correct |
11 |
Correct |
876 ms |
201744 KB |
Output is correct |
12 |
Correct |
9 ms |
65116 KB |
Output is correct |
13 |
Correct |
375 ms |
155760 KB |
Output is correct |
14 |
Correct |
368 ms |
193916 KB |
Output is correct |
15 |
Correct |
588 ms |
155176 KB |
Output is correct |
16 |
Correct |
868 ms |
201872 KB |
Output is correct |
17 |
Correct |
794 ms |
168224 KB |
Output is correct |
18 |
Correct |
1043 ms |
169152 KB |
Output is correct |
19 |
Correct |
949 ms |
195124 KB |
Output is correct |
20 |
Correct |
481 ms |
158168 KB |
Output is correct |
21 |
Correct |
1171 ms |
204816 KB |
Output is correct |
22 |
Correct |
1056 ms |
205196 KB |
Output is correct |
23 |
Correct |
446 ms |
157644 KB |
Output is correct |
24 |
Correct |
380 ms |
196228 KB |
Output is correct |
25 |
Correct |
768 ms |
157236 KB |
Output is correct |
26 |
Correct |
1114 ms |
205536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
65192 KB |
Output is correct |
2 |
Correct |
17 ms |
65188 KB |
Output is correct |
3 |
Correct |
58 ms |
65164 KB |
Output is correct |
4 |
Correct |
16 ms |
65040 KB |
Output is correct |
5 |
Correct |
11 ms |
65112 KB |
Output is correct |
6 |
Correct |
15 ms |
65116 KB |
Output is correct |
7 |
Correct |
713 ms |
166892 KB |
Output is correct |
8 |
Correct |
786 ms |
192784 KB |
Output is correct |
9 |
Correct |
375 ms |
155784 KB |
Output is correct |
10 |
Correct |
879 ms |
202180 KB |
Output is correct |
11 |
Correct |
876 ms |
201744 KB |
Output is correct |
12 |
Correct |
9 ms |
65116 KB |
Output is correct |
13 |
Correct |
375 ms |
155760 KB |
Output is correct |
14 |
Correct |
368 ms |
193916 KB |
Output is correct |
15 |
Correct |
588 ms |
155176 KB |
Output is correct |
16 |
Correct |
868 ms |
201872 KB |
Output is correct |
17 |
Correct |
794 ms |
168224 KB |
Output is correct |
18 |
Correct |
1043 ms |
169152 KB |
Output is correct |
19 |
Correct |
949 ms |
195124 KB |
Output is correct |
20 |
Correct |
481 ms |
158168 KB |
Output is correct |
21 |
Correct |
1171 ms |
204816 KB |
Output is correct |
22 |
Correct |
1056 ms |
205196 KB |
Output is correct |
23 |
Correct |
446 ms |
157644 KB |
Output is correct |
24 |
Correct |
380 ms |
196228 KB |
Output is correct |
25 |
Correct |
768 ms |
157236 KB |
Output is correct |
26 |
Correct |
1114 ms |
205536 KB |
Output is correct |
27 |
Correct |
2391 ms |
190576 KB |
Output is correct |
28 |
Correct |
3271 ms |
199768 KB |
Output is correct |
29 |
Correct |
3456 ms |
224752 KB |
Output is correct |
30 |
Correct |
615 ms |
156800 KB |
Output is correct |
31 |
Correct |
4027 ms |
233276 KB |
Output is correct |
32 |
Correct |
4027 ms |
233824 KB |
Output is correct |
33 |
Correct |
365 ms |
197216 KB |
Output is correct |
34 |
Correct |
2315 ms |
183780 KB |
Output is correct |
35 |
Correct |
3594 ms |
230268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
65192 KB |
Output is correct |
2 |
Correct |
17 ms |
65188 KB |
Output is correct |
3 |
Correct |
58 ms |
65164 KB |
Output is correct |
4 |
Correct |
16 ms |
65040 KB |
Output is correct |
5 |
Correct |
11 ms |
65112 KB |
Output is correct |
6 |
Correct |
15 ms |
65116 KB |
Output is correct |
7 |
Correct |
713 ms |
166892 KB |
Output is correct |
8 |
Correct |
786 ms |
192784 KB |
Output is correct |
9 |
Correct |
375 ms |
155784 KB |
Output is correct |
10 |
Correct |
879 ms |
202180 KB |
Output is correct |
11 |
Correct |
876 ms |
201744 KB |
Output is correct |
12 |
Correct |
9 ms |
65116 KB |
Output is correct |
13 |
Correct |
375 ms |
155760 KB |
Output is correct |
14 |
Correct |
368 ms |
193916 KB |
Output is correct |
15 |
Correct |
588 ms |
155176 KB |
Output is correct |
16 |
Correct |
868 ms |
201872 KB |
Output is correct |
17 |
Correct |
794 ms |
168224 KB |
Output is correct |
18 |
Correct |
1043 ms |
169152 KB |
Output is correct |
19 |
Correct |
949 ms |
195124 KB |
Output is correct |
20 |
Correct |
481 ms |
158168 KB |
Output is correct |
21 |
Correct |
1171 ms |
204816 KB |
Output is correct |
22 |
Correct |
1056 ms |
205196 KB |
Output is correct |
23 |
Correct |
446 ms |
157644 KB |
Output is correct |
24 |
Correct |
380 ms |
196228 KB |
Output is correct |
25 |
Correct |
768 ms |
157236 KB |
Output is correct |
26 |
Correct |
1114 ms |
205536 KB |
Output is correct |
27 |
Correct |
2391 ms |
190576 KB |
Output is correct |
28 |
Correct |
3271 ms |
199768 KB |
Output is correct |
29 |
Correct |
3456 ms |
224752 KB |
Output is correct |
30 |
Correct |
615 ms |
156800 KB |
Output is correct |
31 |
Correct |
4027 ms |
233276 KB |
Output is correct |
32 |
Correct |
4027 ms |
233824 KB |
Output is correct |
33 |
Correct |
365 ms |
197216 KB |
Output is correct |
34 |
Correct |
2315 ms |
183780 KB |
Output is correct |
35 |
Correct |
3594 ms |
230268 KB |
Output is correct |
36 |
Execution timed out |
9083 ms |
237260 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |