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>
using namespace std;
#define pii pair<int, int>
#define fm first
#define t second
const int MAXN = 5e4 + 10;
vector<pii> rec[MAXN];
int ans[MAXN];
void calc(int a, int b) {
for (int i = max(a - 5, 0); i <= b; i++) ans[i] = -1;
ans[a] = 0;
for (int i = a + 1; i <= b; i++) {
for (auto u : rec[i]) {
if (ans[u.fm] != -1) {
if (ans[i] == -1) ans[i] = (ans[u.fm] + u.t);
else ans[i] = min(ans[i], ans[u.fm] + u.t);
}
}
}
}
int32_t main() {
int k, n, m, o;
cin >> k >> n >> m >> o;
for (int i = 0; i < m; i++) {
int a, b, toll;
cin >> a >> b >> toll;
rec[b].push_back({a, toll});
}
for (int i = 0; i < o; i++) {
int a, b;
cin >> a >> b;
calc(a, b);
cout << ans[b] << "\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... |