#include "escape_route.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const long long INF=1e18;
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) {
vector<int> adj[n+1];
for(int i=0;i<m;i++){
adj[a[i]].push_back(i);
adj[b[i]].push_back(i);
}
vector<vector<long long>> dis(n,vector<long long>(n,INF)),dis1(n,vector<long long>(n,-1));
for(int i=0;i<n;i++){
dis1[i][i]=s;
priority_queue<pair<int,int>> pq;
pq.push({s,i});
while(pq.size()){
auto [d,k]=pq.top();
pq.pop();
if(dis1[i][k]!=d)continue;
for(int j:adj[k]){
int to=(a[j]==k?b[j]:a[j]);
int cost=min(c[j]-l[j],dis1[i][k]-l[j]);
if(dis1[i][to]<cost){
dis1[i][to]=cost;
pq.push({cost,to});
}
}
}
}
for(int i=0;i<n;i++){
dis[i][i]=0;
priority_queue<pair<int,int>> pq;
pq.push({0,i});
while(pq.size()){
auto [d,k]=pq.top();
pq.pop();
d=-d;
if(dis[i][k]!=d)continue;
for(int j:adj[k]){
int to=(a[j]==k?b[j]:a[j]);
int d1=(d%s<=c[j]-l[j]?d:(d/s+1)*s);
int cost=d1+l[j];
if(dis[i][to]>cost){
dis[i][to]=cost;
pq.push({-cost,to});
}
}
}
}
vector<long long> ans1(q);
for(int i=0;i<q;i++){
long long a1=u[i],b1=v[i],t1=t[i];
long long ans=INF;
fill(dis[a1].begin(),dis[a1].end(),INF);
dis[a1][a1]=t1;
priority_queue<pair<int,int>> pq;
pq.push({-t1,a1});
while(pq.size()){
auto [d,k]=pq.top();
pq.pop();
d=-d;
if(dis[a1][k]!=d)continue;
for(int j:adj[k]){
int to=(a[j]==k?b[j]:a[j]);
int d1=(d%s<=c[j]-l[j]?d:(d/s+1)*s);
int cost=d1+l[j];
if(dis[a1][to]>cost){
dis[a1][to]=cost;
pq.push({-cost,to});
}
}
}
ans1[i]=dis[a1][b1]-t1;
}
return ans1;
}
Compilation message
escape_route.cpp: In function 'std::vector<long long int> calculate_necessary_time(int, int, long long int, int, std::vector<int>, std::vector<int>, std::vector<long long int>, std::vector<long long int>, std::vector<int>, std::vector<int>, std::vector<long long int>)':
escape_route.cpp:54:19: warning: unused variable 'ans' [-Wunused-variable]
54 | long long ans=INF;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
65112 KB |
Output is correct |
2 |
Incorrect |
22 ms |
65116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9059 ms |
155076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
65112 KB |
Output is correct |
2 |
Incorrect |
22 ms |
65116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
65112 KB |
Output is correct |
2 |
Incorrect |
22 ms |
65116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
65112 KB |
Output is correct |
2 |
Incorrect |
22 ms |
65116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |