#include "escape_route.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
std::vector<long long> calculate_necessary_time(
int n, int m, long long S, int Q, std::vector<int> A, std::vector<int> B,
std::vector<long long> L, std::vector<long long> C, std::vector<int> U,
std::vector<int> V, std::vector<long long> T) {
for (int i = 0; i < m; ++i) {
A.push_back(B[i]);
B.push_back(A[i]);
L.push_back(L[i]);
C.push_back(C[i]);
}
m = A.size();
vector<vector<int>> g(n);
for (int i = 0; i < m; ++i) {
g[A[i]].push_back(i);
}
auto dijkstra = [&](int s, ll t) {
vector<ll> d(n, INF);
d[s] = t;
vector<bool> used(n, false);
for (int it = 0; it < n; ++it) {
int u = -1;
for (int i = 0; i < n; ++i) {
if (!used[i] && (u == -1 || d[i] < d[u])) {
u = i;
}
}
if (d[u] == INF) break;
used[u] = true;
for (int e : g[u]) {
int v = B[e];
ll cur = d[u] + L[e];
if (cur > C[e]) cur += S - d[u] % S;
d[v] = min(d[v], cur);
}
}
return d;
};
vector<vector<ll>> dist0(n);
for (int i = 0; i < n; ++i) {
dist0[i] = dijkstra(i, 0);
}
vector<vector<ll>> dist_edge(m);
for (int i = 0; i < m; ++i) {
dist_edge[i] = dijkstra(A[i], C[i] - L[i]);
for (int v = 0; v < n; ++v) {
if (dist_edge[i][v] <= S) {
dist_edge[i][v] -= C[i] - L[i];
} else {
dist_edge[i][v] = INF;
}
}
}
vector<ll> ans(Q);
for (int i = 0; i < Q; ++i) {
ans[i] = (S - T[i]) % S + dist0[U[i]][V[i]];
}
for (int i = 0; i < n; ++i) {
sort(g[i].begin(), g[i].end(), [&](int ei, int ej) {
return C[ei] - L[ei] > C[ej] - L[ej];
});
}
for (int s = 0; s < n; ++s) {
vector<int> queries;
for (int i = 0; i < Q; ++i) {
if (U[i] == s) {
queries.push_back(i);
}
}
sort(queries.begin(), queries.end(), [&](int i, int j) {
return T[i] > T[j];
});
int qind = 0;
vector<int> ind(n, 0);
vector<ll> d(n, INF);
d[s] = 0;
while (true) {
pair<ll, int> mx = {-1, -1};
for (int u = 0; u < n; ++u) {
if (ind[u] < (int)g[u].size()) {
int e = g[u][ind[u]];
mx = max(mx, {C[e] - L[e] - d[u], u});
}
}
while (qind < (int)queries.size() && T[queries[qind]] > mx.first) {
int i = queries[qind++];
ans[i] = min(ans[i], d[V[i]]);
for (int u = 0; u < n; ++u) {
if (d[u] < INF) {
ans[i] = min(ans[i], S - T[i] + dist0[u][V[i]]);
}
}
}
if (mx.first < 0) break;
int e = g[mx.second][ind[mx.second]++];
for (int i = 0; i < n; ++i) {
if (dist_edge[e][i] < INF) {
d[i] = min(d[i], dist_edge[e][i] + d[mx.second]);
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
65044 KB |
Output is correct |
2 |
Incorrect |
30 ms |
65048 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1711 ms |
154960 KB |
Output is correct |
2 |
Correct |
1733 ms |
172984 KB |
Output is correct |
3 |
Correct |
1698 ms |
154092 KB |
Output is correct |
4 |
Correct |
1771 ms |
182492 KB |
Output is correct |
5 |
Correct |
1780 ms |
182612 KB |
Output is correct |
6 |
Correct |
23 ms |
64980 KB |
Output is correct |
7 |
Correct |
1694 ms |
154988 KB |
Output is correct |
8 |
Correct |
1692 ms |
194492 KB |
Output is correct |
9 |
Correct |
1628 ms |
154908 KB |
Output is correct |
10 |
Correct |
1728 ms |
182064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
65044 KB |
Output is correct |
2 |
Incorrect |
30 ms |
65048 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
65044 KB |
Output is correct |
2 |
Incorrect |
30 ms |
65048 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
65044 KB |
Output is correct |
2 |
Incorrect |
30 ms |
65048 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |