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 fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
int k, n, m, o;
vvii adj;
ll getToll(int u, int v) {
//cerr << "// getToll(" << u << ", " << v << ")\n";
if (u == v) return 0;
if (u/5 >= v/5) return -1;
ll minToll = -1;
for (ii edge : adj[u]) {
ll currToll = getToll(edge.fi, v);
if (currToll == -1) continue;
currToll += edge.se;
if (minToll == -1 || currToll < minToll) minToll = currToll;
}
return minToll;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> k >> n >> m >> o;
adj.assign(n + 20, vii());
for (int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
adj[a].push_back({b, t});
}
for (int i = 0; i < o; i++) {
int a, b;
cin >> a >> b;
if (a > b) swap(a, b);
cout << getToll(a, 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... |