#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const int inf = 1e9;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int k, n, m, q; cin>>k>>n>>m>>q;
vector<pii> g1[n + 1], g2[n + 1];
while (m--){
int x, y, t; cin>>x>>y>>t;
x++; y++;
g1[x].pb({y, t});
g2[y].pb({x, t});
}
while (q--){
int x, y; cin>>x>>y;
x++; y++;
vector<int> dist(n + 1, inf);
dist[x] = 0;
for (int i = x; i <= y; i++){
for (auto [j, t]: g1[i]){
dist[j] = min(dist[j], dist[i] + t);
}
}
cout<<((dist[y] == inf) ? -1 : dist[y])<<"\n";
}
}
# | 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... |