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>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
struct E {
int a, b, w;
};
const int N = 1e5 + 5, INF = 1e9;
E e[N];
int d[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, m, k, o;
cin >> k >> n >> m >> o;
for (int i = 0; i < m; i++) {
cin >> e[i].a >> e[i].b >> e[i].w;
}
sort(e, e + m, [](E x, E y) {
return x.a < y.a;
});
for (int i = 0; i < o; i++) {
int x, y;
cin >> x >> y;
fill(d, d + n, INF);
d[x] = 0;
for (int j = 0; j < m; j++) {
d[e[j].b] = min(d[e[j].b], d[e[j].a] + e[j].w);
}
if (d[y] == INF)
cout << "-1\n";
else
cout << d[y] << "\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... |