#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int k, n, m, q;
cin >> k >> n >> m >> q;
vector<pair<int, int>> E[n];
while (m--) {
int x, y, w;
cin >> x >> y >> w;
E[y].push_back({x, w});
}
while (q--) {
int x, y;
cin >> x >> y;
vector<int> dp(n, (int)2e9);
dp[x] = 0;
for (int i = x + 1; i <= y; i++) {
for (auto [j, w] : E[i])
dp[i] = min(dp[i], dp[j] + w);
}
cout << (dp[y] == (int)2e9 ? -1 : dp[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... |