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;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;}
auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";}
#define debug(X) cerr << "["#X"]: " << X << '\n';
#else
#define debug(X) ;
#endif
#define ll long long
#define all(v) (v).begin(), (v).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define ROF(i,r,l) for(int i=(r);i>=(l);--i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
#define fi first
#define se second
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int k, n, m, o;
cin >> k >> n >> m >> o;
vector<vector<pair<int, int>>> G(n);
REP(i, m) {
int a, b, t;
cin >> a >> b >> t;
G[a].push_back({b, t});
}
constexpr int inf = 1e9;
vector dp(n, vector(n, inf));
REP(j, n) {
dp[j][j] = 0;
ROF(i, n-1, 0) {
for (auto w : G[i]) {
dp[i][j] = min(dp[i][j], w.se+dp[w.fi][j]);
}
}
}
REP(i, o) {
int a, b;
cin >> a >> b;
cout << (dp[a][b]==inf?-1:dp[a][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... |