# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
806970 | YassineBenYounes | Escape Route (JOI21_escape_route) | C++17 | 0 ms | 0 KiB |
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<bits/stdc++.h>
typedef long long ll;
using namespace std;
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
const int mx = 100;
const ll inf = 1e18;
vector<vl> graph[mx];
vector<vl> queries[mx];
bool vis[mx];
ll s;
int n, m, q;
ll ans[mx];
void solve(int st, int target, ll t){
priority_queue<pll, vector<pll>, greater<pll>> pq;
pq.push({t, st});
memset(vis, 0, sizeof vis);
for(int i = 0; i < n;i++){
ans[i] = inf;
}
int k = 0;
ans[st] = t;
while(!pq.empty()){
int node = pq.top().ss;
ll tm = pq.top().ff;
pq.pop();
if(vis[node])continue;
vis[node] = 1;
for(vl adj : graph[node]){
ll nxt = tm + adj[1];
if(adj[1] > adj[2])continue;
ll o = nxt % s;
if((nxt/s) > (tm/s) || o > adj[2]){
nxt = (tm / s + 1) * s + adj[1];
}
ans[adj[0]] = min(ans[adj[0]], nxt);
pq.push({ans[adj[0]], adj[0]});
}
}
//cout << ans[2] << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> m >> s >> q;
for(int i = 0; i < m;i++){
ll a, b, l, c;cin >> a >> b >> l >> c;
graph[a].pb({b, l, c});
graph[b].pb({a, l, c});
}
while(q--){
ll u, v, t;cin >> u >> v >> t;
solve(u, v, t);
cout << ans[v] - t << endl;
}
}