#include "escape_route.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct edge{
int v,l,c;
edge(int v,int l,int c):v(v),l(l),c(c){}
};
std::vector<long long> calculate_necessary_time(
int32_t N, int32_t M, long long S, int32_t Q, std::vector<int32_t> A, std::vector<int32_t> B,
std::vector<long long> L, std::vector<long long> C, std::vector<int32_t> U,
std::vector<int32_t> V, std::vector<long long> T) {
vector<vector<tuple<int,int,int>>> adj(N);
for(int i=0;i<M;i++){
adj[A[i]].emplace_back(B[i],L[i],C[i]);
adj[B[i]].emplace_back(A[i],L[i],C[i]);
}
vector<int> ans(Q);
for(int i=0;i<Q;i++){
priority_queue<pair<int,int>> q;
q.emplace(-T[i],U[i]);
vector<int> visited(N,1e18);
vector<bool> vis(N);
visited[U[i]] = T[i];
while(!q.empty()){
auto [dist,idx] = q.top();q.pop();dist=-dist;
if(vis[idx])continue;
vis[idx]=true;
if(idx==V[i]){
ans[i] = dist-T[i];
break;
}
for(auto[v,l,c]:adj[idx]){
int nxttime = 0;
int currtime = dist%S;
if(currtime<=c-l)nxttime=dist+l;
else {
nxttime = (dist/S)*S+l+S;
}
if(nxttime<visited[v]){
visited[v]=nxttime;
q.emplace(-nxttime,v);
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
65116 KB |
Output is correct |
2 |
Correct |
10 ms |
65196 KB |
Output is correct |
3 |
Correct |
12 ms |
65116 KB |
Output is correct |
4 |
Correct |
8 ms |
65116 KB |
Output is correct |
5 |
Correct |
12 ms |
65112 KB |
Output is correct |
6 |
Correct |
9 ms |
65192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9016 ms |
154968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
65116 KB |
Output is correct |
2 |
Correct |
10 ms |
65196 KB |
Output is correct |
3 |
Correct |
12 ms |
65116 KB |
Output is correct |
4 |
Correct |
8 ms |
65116 KB |
Output is correct |
5 |
Correct |
12 ms |
65112 KB |
Output is correct |
6 |
Correct |
9 ms |
65192 KB |
Output is correct |
7 |
Execution timed out |
9016 ms |
154968 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
65116 KB |
Output is correct |
2 |
Correct |
10 ms |
65196 KB |
Output is correct |
3 |
Correct |
12 ms |
65116 KB |
Output is correct |
4 |
Correct |
8 ms |
65116 KB |
Output is correct |
5 |
Correct |
12 ms |
65112 KB |
Output is correct |
6 |
Correct |
9 ms |
65192 KB |
Output is correct |
7 |
Execution timed out |
9016 ms |
154968 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
65116 KB |
Output is correct |
2 |
Correct |
10 ms |
65196 KB |
Output is correct |
3 |
Correct |
12 ms |
65116 KB |
Output is correct |
4 |
Correct |
8 ms |
65116 KB |
Output is correct |
5 |
Correct |
12 ms |
65112 KB |
Output is correct |
6 |
Correct |
9 ms |
65192 KB |
Output is correct |
7 |
Execution timed out |
9016 ms |
154968 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |