This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ve vector
typedef long long ll;
const int INF = 1e9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int k, n, m, o, a, b, t, u, v, d, dNew;
ve<ve<pair<int, int>>> G;
ve<int> D;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> PQ;
cin >> k >> n >> m >> o;
G = ve<ve<pair<int, int>>>(n);
for (int i = 0; i < m; i++) {
cin >> a >> b >> t;
G[a].push_back({b, t});
}
for (int i = 0; i < o; i++) {
cin >> a >> b;
D = vector<int>(n, INF);
D[a] = 0;
PQ.push({0, a});
while (!PQ.empty()) {
tie(d, u) = PQ.top();
PQ.pop();
for (pair<int, int> e : G[u]) {
tie(v, t) = e;
dNew = d + t;
if (dNew < D[v]) {
D[v] = dNew;
PQ.push({dNew, v});
}
}
}
if (D[b] == INF) cout << -1 << endl;
else cout << D[b] << endl;
}
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... |