# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
806972 | YassineBenYounes | Escape Route (JOI21_escape_route) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<escape_route.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;
}
}