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>
#define forf(i,a,b) for(int i = a; i<=b; i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
struct Edge{
int to;
ll t,c;
};
int n; ll s;
vector<Edge> adj[101];
ll inf =1e18;
ll d[101];
ll dijk(int st ,int en , ll t){
forf(i,0,n) d[i] = inf;
d[st] = t;
priority_queue<pair<ll,int> > pq;
pq.push({-t,st});
while(pq.size()){
int now = pq.top().second;
ll nowt = -pq.top().first;
pq.pop();
if(d[now] < nowt) continue;
for(auto &edge : adj[now]){
ll newt;
if(nowt%s + edge.t <= edge.c) newt = nowt+edge.t;
else newt = s*((nowt/s)+1)+edge.t;
if(newt < d[edge.to]){
d[edge.to] = newt;
pq.push({-newt,edge.to});
}
}
}
return d[en]-t;
}
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) {
n=N;s=S;
vector<ll> ans(Q);
forf(i,0,M-1){
adj[A[i]].push_back({B[i],L[i],C[i]});
adj[B[i]].push_back({A[i],L[i],C[i]});
}
forf(i,0,Q-1){
ans[i]= dijk(U[i],V[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... |