# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1157756 | yf_yusuf | Escape Route (JOI21_escape_route) | C++20 | 0 ms | 0 KiB |
#include "escape_route.h"
#define Free_open(File) freopen((File".in"),"r",stdin);freopen((File".out"),"w",stdout);
#define YF ios_base::sync_with_stdio(0);cout.setf(ios::fixed);
#define YUSUF cout.precision(0);cout.tie(0);cin.tie(0);
#include <bits/stdc++.h>
using namespace std;
#ifdef YF_CHECK
bool Output=1;
#include "g/debug.h"
//#include "g/bigint.h"
//#include "g/text.h"
#else
bool Output=0;
#define deb(x...) 42
#endif
using ll = long long;
//using ld = long double;
using vll = vector <ll>;
using mll = map <ll,ll>;
using pll = pair <ll,ll>;
using vpll= vector <pll>;
template<class T>T MIN(T&a,T b){a=min(a,b);return a;}
template<class T>T MAX(T&a,T b){a=max(a,b);return a;}
#define revers(a) reverse(all(a))
#define all(a) a.begin(),a.end()
#define sortt(a) sort(all(a))
#define sgr v+v+1,tm+1,tr
#define sgl v+v,tl,tm
#define pb push_back
#define ins insert
#define S second
#define F first
#define int ll
ll BP(ll a,ll b,ll mod=1e9+7){
if(b==0)return 1;
ll q=BP(a,b/2,mod);
return ((q*q)%mod*(b%2?a:1ll))%mod;
}
ll dup(ll a,ll b){return (a+b-1)/b;}
ll f(ll x){return x*(x+1)/2;}
const int mod=998244353;
const int INF=1e18+7;
const int inf=1e9+7;
const int N =1e6+7;
struct edge{
ll to,t,b;
};
struct cmp {
bool operator()(const edge &a, const edge &b) const {
return a.t<b.t;
}
};
vector<edge>g[N];
ll n,S;
ll bfs(ll s,ll f,ll t){
set<edge,cmp>q;
q.ins({s,0,t});
vll d(n+1,INF);
d[s]=0;
while(q.size()){
auto [v,D,nowd]=*q.begin();
q.erase({v,D,nowd});
MIN(d[v],D);
for(auto [to,t,b] : g[v]){
if(d[to]>D+t){
if(b>=nowd+t){
q.ins({to,D+t,nowd+t});
MIN(d[to],D+t);
}
if(b>=t){
q.ins({to,D+t+(S-nowd),t});
MIN(d[to],D+t+S-nowd);
}
}
}
}
return d[f];
}
std::vector<long long> calculate_necessary_time(
int N, int M, long long SS, 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) {
ll m,q;
n=N;
m=M;
q=Q;
S=SS;
for(int i=0;i<m;i++){
ll x=A[i],y=B[i],t=L[i],b=C[i];
g[x].pb({y,t,b});
g[y].pb({x,t,b});
}
vll ans;
for(int i=0;i<Q;i++){
ans.pb(bfs(U[i],V[i],T[i]));
}
return ans;
}