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>
#pragma GCC optimize("O3")
using namespace std;
constexpr int INF = 1000000007; //998244353;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int k, n, m, q;
cin >> k >> n >> m >> q;
vector<vector<pair<int, int>>> edges(n);
for (int i = 0; i < m; ++i) {
int a, b, w;
cin >> a >> b >> w;
edges[a].push_back({b, w});
}
vector<int> best(n, INF);
while (q--) {
int a, b;
cin >> a >> b;
fill(best.begin() + a, best.begin() + b + 1, INF);
best[a] = 0;
for (int i = a; i < b; ++i) {
for (auto [next, wt] : edges[i]) {
best[next] = min(best[next], best[i] + wt);
}
}
if (best[b] == INF) cout << -1 << '\n';
else cout << best[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... |