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;
struct Edge {
int v, w;
};
const int MXN = 5e4+5;
const int INF = 1e9;
int k, n, m, o;
vector<Edge> adj[MXN];
int dist[MXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> k >> n >> m >> o;
for(int i = 0; i < m; i++) {
int u, v, w; cin >> u >> v >> w;
adj[u].push_back({v, w});
}
for(int _ = 0; _ < o; _++) {
fill(dist, dist+n, INF);
int a, b; cin >> a >> b;
dist[a] = 0;
for(int i = a; i < b; i++) {
for(auto e : adj[i]) {
dist[e.v] = min(dist[e.v], dist[i]+e.w);
}
}
if(dist[b] == INF) cout << "-1\n";
else cout << dist[b] << "\n";
}
return 0;
}
# | 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... |