# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
623135 | CSQ31 | Escape Route (JOI21_escape_route) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "escape_route.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000;
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll,ll> pii;
ll L[MAXN],C[MAXN];
vector<pii>adj[MAXN];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,q;
ll s;
cin>>n>>m>>s>>q;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b>>L[i]>>C[i];
adj[a].push_back({b,i});
adj[b].push_back({a,i});
}
for(int i=0;i<q;i++){
vector<ll>dist(n,1e18);
int U,V;
ll T;
cin>>U>>V>>T;
priority_queue<pii,vector<pii>,greater<pii>>pq;
pq.push({T,U});
dist[U] = T;
while(!pq.empty()){
pii v = pq.top();
pq.pop();
int f = v.se;
ll mod = v.fi%s;
if(v.fi != dist[f])continue;
for(pii x:adj[v.se]){
int to = x.fi;
//mod+L[x.se] <= C[x.se]
if(mod+L[x.se] <= C[x.se]){
if(dist[to] > dist[f] + L[x.se]){
dist[to] = dist[f] + L[x.se];
pq.push({dist[to],to});
}
}else{
if(dist[to] > dist[f] + s-mod + L[x.se]){
dist[to] = dist[f] + s-mod + L[x.se];
pq.push({dist[to],to});
}
}
}
}
// for(int i=0;i<n;i++)cout<<dist[i]<<" ";
// cout<<'\n';
cout<<dist[V]-T<<'\n';
}
}