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];
pair<bitset<mxN>, vector<ll>> dijkstra(int s, ll t) {
bitset<mxN> vis; vis.reset();
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();
vis[u] = 1;
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 make_pair(vis,dist);
}
map<ll, bitset<mxN>> bounds[mxN];
bitset<mxN> ok[mxN][mxN];
vector<ll> zdist[mxN];
void dnc(ll s, ll e, int i, bitset<mxN> mn, bitset<mxN> mx) {
bounds[i][s] = mn;
FOR(j,s+1,e-1){
auto cur = dijkstra(i,j).first;
if (cur != mn) bounds[i][j] = mn = cur;
}
//if (s+1 == e) {
// bounds[i][s] = mn;
// return;
//}
//ll m = (s+e)/2;
//auto cur = dijkstra(i,m).first;
//if (mn != cur) dnc(s,m,i,mn,cur);
//if (cur != mx) dnc(m,e,i,cur,mx);
}
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){
auto mn = dijkstra(i,0);
auto mx = dijkstra(i,S+1);
//dnc(0,S+1,i,mn.first,mx.first);
//for (auto& x : bounds[i]) {
// TRACE(i _ x.first _ x.second.count());
//}
ok[i][0] = mn.first;
zdist[i] = mn.second;
}
FOR(k,1,6){
FOR(i,0,N-1){
ok[i][k].reset();
FOR(j,0,N-1) if (ok[i][k-1][j]) {
ok[i][k] |= ok[j][k-1];
}
}
}
//FOR(i,0,N-1){
// FOR(k,0,6){
// TRACE(i _ ok[i][k]);
// }
// cout <<endl;
//}
vector<ll> ans(Q);
FOR(i,0,Q-1){
//auto st = (--bounds[U[i]].lower_bound(T[i]+1))->second;
auto d = dijkstra(U[i],T[i]);
auto st = d.first;
if (st[V[i]]) {
ans[i] = d.second[V[i]] - T[i];
} else {
ans[i] = S;
RFOR(k,6,0){
bitset<mxN> tmp; tmp.reset();
FOR(j,0,N-1) if (st[j]) {
tmp |= ok[j][k];
}
if (!tmp[V[i]]) {
st |= tmp;
ans[i] += (1<<k) * S;
}
}
ll mn = S+1;
FOR(j,0,N-1) if (st[j]) {
mn = min(mn, zdist[j][V[i]]);
}
//TRACE( i _ ans[i] _ mn );
ans[i] += mn;
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... |