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 TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
const int mxN = 90;
typedef long long ll;
struct Edge { int v; ll l, c; };
int N;
ll S;
vector<Edge> al[mxN];
vector<ll> zdist[mxN];
vector<ll> dijkstra(int s, int t) {
vector<ll> dist(N,S+1);
priority_queue<pair<ll,int>> pq;
pq.push(make_pair(-t,s)); dist[s] = t;
while (!pq.empty()) {
int u = pq.top().second;
ll w = -pq.top().first;
pq.pop();
if (w > dist[u]) continue;
for (auto& e : al[u]) {
if (w+e.l <= e.c && w+e.l < dist[e.v]) {
dist[e.v] = w+e.l;
pq.push(make_pair(-dist[e.v],e.v));
}
}
}
return dist;
}
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;
FOR(i,0,M-1){
al[A[i]].push_back({B[i],L[i],C[i]});
al[B[i]].push_back({A[i],L[i],C[i]});
}
FOR(i,0,N-1){
zdist[i] = dijkstra(i,0);
}
vector<ll> ans(Q);
FOR(i,0,Q-1){
vector<ll> mdist = dijkstra(U[i],T[i]), tmp;
//FOR(j,0,N-1){ cout << mdist[j] << ' '; } cout << endl;
ans[i] -= T[i];
if (mdist[V[i]] < S+1) {
ans[i] += mdist[V[i]];
continue;
}
ll t = S;
while (true) {
tmp.assign(N,S+1);
FOR(j,0,N-1) if (mdist[j] < S+1) {
FOR(k,0,N-1){
tmp[k] = min(tmp[k], zdist[j][k]);
}
}
swap(mdist,tmp);
if (mdist[V[i]] < S+1) {
ans[i] += t + mdist[V[i]];
break;
} else t += S;
}
}
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... |