이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |