This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Bismi ALlah
#include "bits/stdc++.h"
using namespace std;
#define int long long
signed main () {
int n, m, k, query;
cin >> k >> n >> m >> query;
vector<pair <int,int>> g[n];
for(int i = 0; i < m; i ++) {
int u, v;
cin >> u >> v;
int w;
cin >> w;
g[u].push_back({v, w});
}
int dp[n][k];
for(int i = 0; i < n; i ++) {
for(int j = 0; j < k; j ++) dp[i][j] = LLONG_MAX;
}
for(int j = 0; j < k; j ++) {
dp[j][j] = 0;
for(int i = 0; i < n; i ++) {
if(dp[i][j] != LLONG_MAX) {
for(auto [u, w] : g[i]) {
dp[u][j] = min(dp[u][j], dp[i][j] + w);
}
}
}
}
while(query --) {
int a, b;
cin >> a >> b;
int mn = LLONG_MAX;
for(int i = 0; i < k; i ++) {
if(dp[b][i] == LLONG_MAX || dp[a][i] == LLONG_MAX) continue;
mn = min(mn, dp[b][i] - dp[a][i]);
}
if(mn == LLONG_MAX) cout << -1 << "\n";
else cout << mn << "\n";
}
return 0;
}
Compilation message (stderr)
toll.cpp: In function 'int main()':
toll.cpp:27:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for(auto [u, w] : g[i]) {
| ^
# | 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... |