This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "escape_route.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
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<vector<int>> distances(N,vector<int>(N));
for(int i=0;i<N;i++){
priority_queue<pair<int,int>> q;
q.emplace(0,i);
vector<int> visited(N,1e18);
vector<bool> vis(N);
visited[i] = 0;
while(!q.empty()){
auto [dist,idx] = q.top();q.pop();dist=-dist;
if(vis[idx])continue;
vis[idx]=true;
for(auto[v,l,c]:adj[idx])if(!vis[v]){
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);
}
}
}
distances[i]=visited;
}
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])if(dist+l<visited[v] and dist<=c-l){
visited[v]=dist+l;
q.emplace(-dist-l,v);
}
}
if(ans[i])continue;
ans[i]=1e18;
for(int x=0;x<N;x++)if(vis[x])ans[i]=min(ans[i],(visited[x]/S)*S+S+distances[x][V[i]]);
ans[i]-=T[i];
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |